summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <quaker66@gmail.com>2014-02-17 16:29:51 +0000
committerDaniel Kolesa <quaker66@gmail.com>2014-02-17 16:29:51 +0000
commitbe58d66d1812ae05a7dd80dc166fbfc78d6544a3 (patch)
tree742ef08f053e38d6cc6aac90c16bc51d38c76d9a
parent27e488dc042b1eada5accdd3236c0f6146d70c22 (diff)
cleanups, optimizations
-rw-r--r--engine_sw_sdl.lua10
-rw-r--r--engine_x11.lua19
-rw-r--r--main.lua4
-rw-r--r--tests/image_data_ycbcr601pl.lua10
-rw-r--r--tests/image_data_ycbcr601pl_map_solid_rotate.lua10
-rw-r--r--tests/image_data_ycbcr601pl_wide_stride.lua10
-rw-r--r--ui.lua14
-rw-r--r--util.lua45
8 files changed, 83 insertions, 39 deletions
diff --git a/engine_sw_sdl.lua b/engine_sw_sdl.lua
index e6fa5f0..2bc2862 100644
--- a/engine_sw_sdl.lua
+++ b/engine_sw_sdl.lua
@@ -1,12 +1,12 @@
1local ffi = require("ffi") 1local ffi = require("ffi")
2local ffi_cast = ffi.cast 2local ffi_cast = ffi.cast
3local ffi_str = ffi.string 3local ffi_str = ffi.string
4
5local io_write = io.write
6local bor = bit.bor 4local bor = bit.bor
7 5
8local util = require("util") 6local util = require("util")
9 7
8local write_out = util.write_out
9
10local lsdl = util.load_lib("SDL") 10local lsdl = util.load_lib("SDL")
11if not lsdl then return { init = function() end } end 11if not lsdl then return { init = function() end } end
12local levas = util.get_lib("evas") 12local levas = util.get_lib("evas")
@@ -402,7 +402,7 @@ local engine_sdl_setup = function(engine, width, height)
402 if not einfo then return false end 402 if not einfo then return false end
403 -- video, noparachute 403 -- video, noparachute
404 if lsdl.SDL_Init(bor(0x00100000, 0x00000020)) < 0 then 404 if lsdl.SDL_Init(bor(0x00100000, 0x00000020)) < 0 then
405 io_write("SDL_Init failed with ", ffi_str(lsdl.SDL_GetError())) 405 write_out("SDL_Init failed with " .. ffi_str(lsdl.SDL_GetError()))
406 lsdl.SDL_Quit() 406 lsdl.SDL_Quit()
407 return false 407 return false
408 end 408 end
@@ -410,7 +410,7 @@ local engine_sdl_setup = function(engine, width, height)
410 einfo.info.switch_data = lsdl.SDL_SetVideoMode(width, height, 32, 410 einfo.info.switch_data = lsdl.SDL_SetVideoMode(width, height, 32,
411 bor(0x00000001, 0x40000000)) 411 bor(0x00000001, 0x40000000))
412 if einfo.info.switch_data == nil then 412 if einfo.info.switch_data == nil then
413 io_write("SDL_SetVideoMode failed!\n") 413 write_out("SDL_SetVideoMode failed!\n")
414 lsdl.SDL_Quit() 414 lsdl.SDL_Quit()
415 return false 415 return false
416 end 416 end
@@ -431,7 +431,7 @@ local engine_sdl_setup = function(engine, width, height)
431 flip_cb = einfo.info.func.switch_buffer 431 flip_cb = einfo.info.func.switch_buffer
432 if levas.evas_engine_info_set(evas, ffi.cast("Evas_Engine_Info*", einfo)) 432 if levas.evas_engine_info_set(evas, ffi.cast("Evas_Engine_Info*", einfo))
433 == 0 then 433 == 0 then
434 io_write("evas_engine_info_set() for engine 'sdl' with " 434 write_out("evas_engine_info_set() for engine 'sdl' with "
435 .. "'buffer' backend failed.\n") 435 .. "'buffer' backend failed.\n")
436 lsdl.SDL_Quit() 436 lsdl.SDL_Quit()
437 return false 437 return false
diff --git a/engine_x11.lua b/engine_x11.lua
index 08f0d4c..d53660a 100644
--- a/engine_x11.lua
+++ b/engine_x11.lua
@@ -1,9 +1,8 @@
1local ffi = require("ffi") 1local ffi = require("ffi")
2
3local io_write = io.write
4
5local util = require("util") 2local util = require("util")
6 3
4local write_out = util.write_out
5
7ffi.cdef [[ 6ffi.cdef [[
8typedef struct { 7typedef struct {
9 unsigned long background_pixmap; 8 unsigned long background_pixmap;
@@ -358,7 +357,7 @@ local engine_x11_setup = function(engine, width, height, rmth)
358 local einfo = ffi.cast(info_struct[rmth], 357 local einfo = ffi.cast(info_struct[rmth],
359 levas.evas_engine_info_get(evas)) 358 levas.evas_engine_info_get(evas))
360 if einfo == nil then 359 if einfo == nil then
361 io_write("Evas does not suport the " .. engine_name[rmth] 360 write_out("Evas does not suport the " .. engine_name[rmth]
362 .. " Engine\n") 361 .. " Engine\n")
363 xlib.XCloseDisplay(disp) 362 xlib.XCloseDisplay(disp)
364 return false 363 return false
@@ -382,7 +381,7 @@ local engine_x11_setup = function(engine, width, height, rmth)
382 einfo.info.rotation = 0 381 einfo.info.rotation = 0
383 einfo.info.debug = 0 382 einfo.info.debug = 0
384if nil then -- EVAS_FRAME_QUEUING 383if nil then -- EVAS_FRAME_QUEUING
385 local render_mode = os.getenv("EVAS_RENDER_MODE") 384 local render_mode = util.getenv("EVAS_RENDER_MODE")
386 if render_mode and render_mode == "non-blocking" then 385 if render_mode and render_mode == "non-blocking" then
387 einfo.render_mode = levas.EVAS_RENDER_MODE_NONBLOCKING 386 einfo.render_mode = levas.EVAS_RENDER_MODE_NONBLOCKING
388 end 387 end
@@ -407,7 +406,7 @@ end
407 einfo.info.drawable = win 406 einfo.info.drawable = win
408 if levas.evas_engine_info_set(evas, ffi.cast("Evas_Engine_Info*", einfo)) 407 if levas.evas_engine_info_set(evas, ffi.cast("Evas_Engine_Info*", einfo))
409 == 0 then 408 == 0 then
410 io_write("Evas can not setup the informatins of the " 409 write_out("Evas can not setup the informatins of the "
411 .. engine_name[rmth] .. " Engine\n") 410 .. engine_name[rmth] .. " Engine\n")
412 xlib.XDestroyWindow(disp, win) 411 xlib.XDestroyWindow(disp, win)
413 xlib.XCloseDisplay(disp, win) 412 xlib.XCloseDisplay(disp, win)
@@ -492,7 +491,9 @@ local evtypes = {
492 if kstr ~= nil then 491 if kstr ~= nil then
493 kstr = ffi.string(kstr) 492 kstr = ffi.string(kstr)
494 if modkeys[kstr] then 493 if modkeys[kstr] then
495 levas.evas_key_modifier_on(evas, kstr:sub(1, #kstr - 2)) 494 local dup = ffi.new("char[?]", #kstr + 1, kstr)
495 dup[#kstr - 2] = 0
496 levas.evas_key_modifier_on(evas, dup)
496 elseif lockkeys[kstr] then 497 elseif lockkeys[kstr] then
497 if levas.evas_key_lock_is_set(levas.evas_key_lock_get( 498 if levas.evas_key_lock_is_set(levas.evas_key_lock_get(
498 evas), kstr) then 499 evas), kstr) then
@@ -512,7 +513,9 @@ local evtypes = {
512 if kstr ~= nil then 513 if kstr ~= nil then
513 kstr = ffi.string(kstr) 514 kstr = ffi.string(kstr)
514 if modkeys[kstr] then 515 if modkeys[kstr] then
515 levas.evas_key_modifier_off(evas, kstr:sub(1, #kstr - 2)) 516 local dup = ffi.new("char[?]", #kstr + 1, kstr)
517 dup[#kstr - 2] = 0
518 levas.evas_key_modifier_off(evas, dup)
516 end 519 end
517 levas.evas_event_feed_key_up(evas, kstr, kstr, nil, nil, 0, nil) 520 levas.evas_event_feed_key_up(evas, kstr, kstr, nil, nil, 0, nil)
518 end 521 end
diff --git a/main.lua b/main.lua
index fa7d7fa..1f4058b 100644
--- a/main.lua
+++ b/main.lua
@@ -430,7 +430,7 @@ local main = function(args)
430 430
431 local prefix = dtdir 431 local prefix = dtdir
432 if not prefix then 432 if not prefix then
433 prefix = os.getenv("LUAXPEDITE_FONTS_DIR") 433 prefix = util.getenv("LUAXPEDITE_FONTS_DIR")
434 end 434 end
435 if not prefix then 435 if not prefix then
436 prefix = "./data" 436 prefix = "./data"
@@ -465,4 +465,4 @@ local main = function(args)
465 levas.evas_shutdown() 465 levas.evas_shutdown()
466 return 0 466 return 0
467end 467end
468os.exit(main(arg)) \ No newline at end of file 468util.exit(main(arg)) \ No newline at end of file
diff --git a/tests/image_data_ycbcr601pl.lua b/tests/image_data_ycbcr601pl.lua
index b832b24..8762134 100644
--- a/tests/image_data_ycbcr601pl.lua
+++ b/tests/image_data_ycbcr601pl.lua
@@ -3,7 +3,11 @@ local util = require("util")
3local C = ffi.C 3local C = ffi.C
4local levas = util.get_lib("evas") 4local levas = util.get_lib("evas")
5 5
6ffi.cdef [[ size_t fread (void *ptr, size_t size, size_t n, void *stream); ]] 6ffi.cdef [[
7 void *fopen(const char *fname, const char *mode);
8 int fclose(void *stream);
9 size_t fread(void *ptr, size_t size, size_t n, void *stream);
10]]
7 11
8return function(ui) 12return function(ui)
9 return "data.png", "Image Data YCbCr 601 Pointer List", 14.7573, function() 13 return "data.png", "Image Data YCbCr 601 Pointer List", 14.7573, function()
@@ -30,14 +34,14 @@ return function(ui)
30 levas.evas_object_image_fill_set(image, 0, 0, 640, 480) 34 levas.evas_object_image_fill_set(image, 0, 0, 640, 480)
31 levas.evas_object_resize(image, 640, 480) 35 levas.evas_object_resize(image, 640, 480)
32 levas.evas_object_show(image) 36 levas.evas_object_show(image)
33 local f = io.open(util.build_path("tp.yuv"), "rb") 37 local f = C.fopen(util.build_path("tp.yuv"), "rb")
34 yp = ffi.new("unsigned char[?]", 640 * 480) 38 yp = ffi.new("unsigned char[?]", 640 * 480)
35 up = ffi.new("unsigned char[?]", 320 * 240) 39 up = ffi.new("unsigned char[?]", 320 * 240)
36 vp = ffi.new("unsigned char[?]", 320 * 240) 40 vp = ffi.new("unsigned char[?]", 320 * 240)
37 C.fread(yp, 640 * 480, 1, f) 41 C.fread(yp, 640 * 480, 1, f)
38 C.fread(up, 320 * 240, 1, f) 42 C.fread(up, 320 * 240, 1, f)
39 C.fread(vp, 320 * 240, 1, f) 43 C.fread(vp, 320 * 240, 1, f)
40 f:close() 44 C.fclose(f)
41 local data = ffi.cast("unsigned char**", 45 local data = ffi.cast("unsigned char**",
42 levas.evas_object_image_data_get(image, 1)) 46 levas.evas_object_image_data_get(image, 1))
43 local lp = data 47 local lp = data
diff --git a/tests/image_data_ycbcr601pl_map_solid_rotate.lua b/tests/image_data_ycbcr601pl_map_solid_rotate.lua
index 60f8b58..a2d5a6f 100644
--- a/tests/image_data_ycbcr601pl_map_solid_rotate.lua
+++ b/tests/image_data_ycbcr601pl_map_solid_rotate.lua
@@ -3,7 +3,11 @@ local util = require("util")
3local C = ffi.C 3local C = ffi.C
4local levas = util.get_lib("evas") 4local levas = util.get_lib("evas")
5 5
6ffi.cdef [[ size_t fread (void *ptr, size_t size, size_t n, void *stream); ]] 6ffi.cdef [[
7 void *fopen(const char *fname, const char *mode);
8 int fclose(void *stream);
9 size_t fread(void *ptr, size_t size, size_t n, void *stream);
10]]
7 11
8local names = { 12local names = {
9 "Image Data YCbCr 601 Pointer List Map Solid Rotate", 13 "Image Data YCbCr 601 Pointer List Map Solid Rotate",
@@ -40,14 +44,14 @@ return function(ui, variant)
40 levas.evas_object_image_smooth_scale_set(image, (variant == 2) 44 levas.evas_object_image_smooth_scale_set(image, (variant == 2)
41 and 0 or 1) 45 and 0 or 1)
42 levas.evas_object_show(image) 46 levas.evas_object_show(image)
43 local f = io.open(util.build_path("tp.yuv"), "rb") 47 local f = C.fopen(util.build_path("tp.yuv"), "rb")
44 yp = ffi.new("unsigned char[?]", 640 * 480) 48 yp = ffi.new("unsigned char[?]", 640 * 480)
45 up = ffi.new("unsigned char[?]", 320 * 240) 49 up = ffi.new("unsigned char[?]", 320 * 240)
46 vp = ffi.new("unsigned char[?]", 320 * 240) 50 vp = ffi.new("unsigned char[?]", 320 * 240)
47 C.fread(yp, 640 * 480, 1, f) 51 C.fread(yp, 640 * 480, 1, f)
48 C.fread(up, 320 * 240, 1, f) 52 C.fread(up, 320 * 240, 1, f)
49 C.fread(vp, 320 * 240, 1, f) 53 C.fread(vp, 320 * 240, 1, f)
50 f:close() 54 C.fclose(f)
51 local data = ffi.cast("unsigned char**", 55 local data = ffi.cast("unsigned char**",
52 levas.evas_object_image_data_get(image, 1)) 56 levas.evas_object_image_data_get(image, 1))
53 local lp = data 57 local lp = data
diff --git a/tests/image_data_ycbcr601pl_wide_stride.lua b/tests/image_data_ycbcr601pl_wide_stride.lua
index 5efe4c8..f15ffe4 100644
--- a/tests/image_data_ycbcr601pl_wide_stride.lua
+++ b/tests/image_data_ycbcr601pl_wide_stride.lua
@@ -4,7 +4,11 @@ local util = require("util")
4local C = ffi.C 4local C = ffi.C
5local levas = util.get_lib("evas") 5local levas = util.get_lib("evas")
6 6
7ffi.cdef [[ size_t fread (void *ptr, size_t size, size_t n, void *stream); ]] 7ffi.cdef [[
8 void *fopen(const char *fname, const char *mode);
9 int fclose(void *stream);
10 size_t fread(void *ptr, size_t size, size_t n, void *stream);
11]]
8 12
9local band, bnot = bit.band, bit.bnot 13local band, bnot = bit.band, bit.bnot
10 14
@@ -59,14 +63,14 @@ return function(ui)
59 levas.evas_object_image_fill_set(image, 0, 0, 640, 480) 63 levas.evas_object_image_fill_set(image, 0, 0, 640, 480)
60 levas.evas_object_resize(image, 640, 480) 64 levas.evas_object_resize(image, 640, 480)
61 levas.evas_object_show(image) 65 levas.evas_object_show(image)
62 local f = io.open(util.build_path("tp.yuv"), "rb") 66 local f = C.fopen(util.build_path("tp.yuv"), "rb")
63 yp = ffi.new("unsigned char[?]", 640 * 480) 67 yp = ffi.new("unsigned char[?]", 640 * 480)
64 up = ffi.new("unsigned char[?]", 320 * 240) 68 up = ffi.new("unsigned char[?]", 320 * 240)
65 vp = ffi.new("unsigned char[?]", 320 * 240) 69 vp = ffi.new("unsigned char[?]", 320 * 240)
66 C.fread(yp, 640 * 480, 1, f) 70 C.fread(yp, 640 * 480, 1, f)
67 C.fread(up, 320 * 240, 1, f) 71 C.fread(up, 320 * 240, 1, f)
68 C.fread(vp, 320 * 240, 1, f) 72 C.fread(vp, 320 * 240, 1, f)
69 f:close() 73 C.fclose(f)
70 local data = ffi_cast("unsigned char**", 74 local data = ffi_cast("unsigned char**",
71 levas.evas_object_image_data_get(image, 1)) 75 levas.evas_object_image_data_get(image, 1))
72 local lp 76 local lp
diff --git a/ui.lua b/ui.lua
index 914031d..54bc603 100644
--- a/ui.lua
+++ b/ui.lua
@@ -3,12 +3,12 @@
3local ffi = require("ffi") 3local ffi = require("ffi")
4local C = ffi.C 4local C = ffi.C
5 5
6local io_write = io.write
7local collectgarbage = collectgarbage 6local collectgarbage = collectgarbage
8local require = require 7local require = require
9 8
10local util = require("util") 9local util = require("util")
11local get_time = util.get_time 10local get_time = util.get_time
11local write_out = util.write_out
12 12
13local p_fps = 0 13local p_fps = 0
14local key_func, loop_func 14local key_func, loop_func
@@ -67,8 +67,8 @@ local ui_fps_std = function(name, t, f)
67 if f >= loops and not test_done then 67 if f >= loops and not test_done then
68 local fps = f / t 68 local fps = f / t
69 ui_fps(fps) 69 ui_fps(fps)
70 io_write(("%4.2f , %s\n"):format(fps, name)) 70 write_out(("%4.2f , %s\n"):format(fps, name))
71 --io_write(("Memory usage: %d\n"):format(collectgarbage("count"))) 71 --write_out(("Memory usage: %d\n"):format(collectgarbage("count")))
72 test_done = true 72 test_done = true
73 end 73 end
74end 74end
@@ -146,7 +146,7 @@ local ui_all; ui_all = function()
146 else C.snprintf(datestr, 1024, "unknown") end 146 else C.snprintf(datestr, 1024, "unknown") end
147 --print(("%5.2f , EVAS SPEED"):format(fps / t_count)) 147 --print(("%5.2f , EVAS SPEED"):format(fps / t_count))
148 if cmp_report then 148 if cmp_report then
149 io_write(("%5.2f , EVAS SPEED (WEIGHTED), " 149 write_out(("%5.2f , EVAS SPEED (WEIGHTED), "
150 .. "tn, %i , " 150 .. "tn, %i , "
151 .. "t, %s , " 151 .. "t, %s , "
152 .. "ev , %i.%i.%i.%i , " 152 .. "ev , %i.%i.%i.%i , "
@@ -161,7 +161,7 @@ local ui_all; ui_all = function()
161 levas.evas_version.revision, profile.name, win_w, win_h, 161 levas.evas_version.revision, profile.name, win_w, win_h,
162 loops, engine[1], fullscreen and 1 or 0)) 162 loops, engine[1], fullscreen and 1 or 0))
163 else 163 else
164 io_write(("\n#####Test Result#####\n" 164 write_out(("\n#####Test Result#####\n"
165 .. "evas fps speed: %5.2f\n" 165 .. "evas fps speed: %5.2f\n"
166 .. "evas fps speed(weighted): %5.2f\n" 166 .. "evas fps speed(weighted): %5.2f\n"
167 .. "testcase count: %i\n" 167 .. "testcase count: %i\n"
@@ -230,7 +230,7 @@ local ui_num = function(n)
230 end 230 end
231 avgw = avgw / wn 231 avgw = avgw / wn
232 if t_count > 0 then 232 if t_count > 0 then
233 io_write(("%5.2f , EVAS SPEED (WEIGHTED)\n") 233 write_out(("%5.2f , EVAS SPEED (WEIGHTED)\n")
234 :format(wfps / (t_count * avgw))) 234 :format(wfps / (t_count * avgw)))
235 end 235 end
236end 236end
@@ -513,7 +513,7 @@ M.setup = function(conf)
513 local j = 1 513 local j = 1
514 for i = 1, #menu do 514 for i = 1, #menu do
515 if menu[i].weight then 515 if menu[i].weight then
516 io_write(("%3i - %s (Weight %0.2f)\n"):format(j, 516 write_out(("%3i - %s (Weight %0.2f)\n"):format(j,
517 menu[i].text, menu[i].weight)) 517 menu[i].text, menu[i].weight))
518 j = j + 1 518 j = j + 1
519 end 519 end
diff --git a/util.lua b/util.lua
index 4769e42..4160e0f 100644
--- a/util.lua
+++ b/util.lua
@@ -1047,6 +1047,36 @@ M.random = function()
1047 return bor(lsh(r1, 16), r2) 1047 return bor(lsh(r1, 16), r2)
1048end 1048end
1049 1049
1050ffi.cdef [[
1051 char *getenv(const char *name);
1052 void exit(int status);
1053]]
1054
1055local C = ffi.C
1056local ffi_str = ffi.string
1057
1058M.getenv = function(name)
1059 local v = C.getenv(name)
1060 return (v ~= nil) and ffi_str(v) or nil
1061end
1062
1063M.exit = function(status)
1064 C.exit(status or 0)
1065end
1066
1067ffi.cdef [[
1068 extern void *stdout, *stderr;
1069 int fputs (const char *str, void *stream);
1070]]
1071
1072M.write_out = function(str)
1073 C.fputs(str, C.stdout)
1074end
1075
1076M.write_err = function(str)
1077 C.fputs(str, C.stderr)
1078end
1079
1050local resolutions = { 1080local resolutions = {
1051 { "qvga", 320 , 240 }, 1081 { "qvga", 320 , 240 },
1052 { "qvga-p", 240 , 320 }, 1082 { "qvga-p", 240 , 320 },
@@ -1077,7 +1107,7 @@ local engines
1077 1107
1078local help = function() 1108local help = function()
1079 local i 1109 local i
1080 io.stderr:write([[No engine selected. 1110 M.write_err([[No engine selected.
1081 1111
1082Options: 1112Options:
1083 -datadir path/to/data 1113 -datadir path/to/data
@@ -1095,14 +1125,14 @@ Where ENGINE can be one of:
1095]]) 1125]])
1096 1126
1097 for i = 1, #engines do 1127 for i = 1, #engines do
1098 io.stderr:write(" ", engines[i][1]) 1128 M.write_err(" ", engines[i][1])
1099 end 1129 end
1100 io.stderr:write("\nWhere PROFILE can be one of:\n") 1130 M.write_err("\nWhere PROFILE can be one of:\n")
1101 for i = 1, #resolutions do 1131 for i = 1, #resolutions do
1102 io.stderr:write(" ", resolutions[i][1]) 1132 M.write_err(" ", resolutions[i][1])
1103 end 1133 end
1104 io.stderr:write("\n") 1134 M.write_err("\n")
1105 os.exit(-1) 1135 M.exit(-1)
1106end 1136end
1107 1137
1108local econf 1138local econf
@@ -1194,7 +1224,7 @@ M.parse_args = function(args, conf, engs)
1194 conf.loops = 128 1224 conf.loops = 128
1195 end 1225 end
1196 if not has.datadir then 1226 if not has.datadir then
1197 conf.datadir = os.getenv("LUAXPEDITE_DATA_DIR") 1227 conf.datadir = M.getenv("LUAXPEDITE_DATA_DIR")
1198 if not conf.datadir then 1228 if not conf.datadir then
1199 conf.datadir = "./data" 1229 conf.datadir = "./data"
1200 end 1230 end
@@ -1209,7 +1239,6 @@ M.help = help
1209 1239
1210local ffi_new = ffi.new 1240local ffi_new = ffi.new
1211local ffi_load = ffi.load 1241local ffi_load = ffi.load
1212local C = ffi.C
1213local pcall = pcall 1242local pcall = pcall
1214 1243
1215local loaded_libs = {} 1244local loaded_libs = {}