forked from izaya/LuPPC
Why not just do it the hard way?
This commit is contained in:
parent
5082a4104c
commit
af670a7af3
@ -16,4 +16,5 @@ extern char lua_textgpu[];
|
||||
extern char lua_util_buffer[];
|
||||
extern char lua_util_color[];
|
||||
extern char lua_util_random[];
|
||||
extern char lua_winapigpu[];
|
||||
#endif
|
||||
|
@ -30,4 +30,9 @@ void internet_start(lua_State *L);
|
||||
void event_prepare();
|
||||
int event_pull(int timeout);
|
||||
|
||||
#ifdef _WIN32
|
||||
void winapigpu_init(lua_State* L);
|
||||
int winapigpu_events();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -58,6 +58,12 @@ static void add_events(struct timeval* timeout) {
|
||||
|
||||
|
||||
int event_pull(int _timeout) {
|
||||
int n = 0;
|
||||
#ifdef _WIN32
|
||||
n = winapigpu_events();
|
||||
if(n > 0) return n;
|
||||
#endif
|
||||
|
||||
if(_timeout > 0) { /* wait max this much time for event */
|
||||
struct timeval timeout = {_timeout / 1000, (_timeout % 1000) * 1000};
|
||||
add_events(&timeout);
|
||||
@ -70,7 +76,7 @@ int event_pull(int _timeout) {
|
||||
event_base_loop(base, EVLOOP_ONCE);
|
||||
}
|
||||
|
||||
int n = nevt;
|
||||
n = nevt;
|
||||
nevt = 0;
|
||||
return n;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ void setup_modules(lua_State *L) {
|
||||
pushstuple(L, "sandbox", lua_sandbox);
|
||||
pushstuple(L, "textgpu", lua_textgpu);
|
||||
pushstuple(L, "fbgpu", lua_fbgpu);
|
||||
pushstuple(L, "winapigpu", lua_winapigpu);
|
||||
pushstuple(L, "color", lua_util_color);
|
||||
pushstuple(L, "random", lua_util_random);
|
||||
pushstuple(L, "buffer", lua_util_buffer);
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
//#include <sys/statvfs.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@ -27,6 +26,9 @@ void run_init(int argc, char **argv) {
|
||||
setup_modules (L);
|
||||
luanative_start (L);
|
||||
internet_start (L);
|
||||
#ifdef _WIN32
|
||||
winapigpu_init (L);
|
||||
#endif
|
||||
fb_start (L);
|
||||
termutils_start (L);
|
||||
event_prepare();
|
||||
|
89
src/c/winapigpu.c
Normal file
89
src/c/winapigpu.c
Normal file
@ -0,0 +1,89 @@
|
||||
#ifdef _WIN32
|
||||
#include "res.h"
|
||||
#include "lupi.h"
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define WINDOW_CLASS "LuPi2 GPU"
|
||||
#define WINDOW_TITLE "LuPi2"
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
switch(msg) {
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
exit(0); /* TODO: Push exit event? Or just remove gpu component?? */
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_open(lua_State *L) {
|
||||
WNDCLASSEX wc;
|
||||
HWND hwnd;
|
||||
|
||||
wc.cbSize = sizeof(WNDCLASSEX);
|
||||
wc.style = 0;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = GetModuleHandle(NULL);
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = WINDOW_CLASS;
|
||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
if(!RegisterClassEx(&wc)) {
|
||||
lua_pushboolean(L, 0);
|
||||
lua_pushstring(L, "Window registration failed");
|
||||
return 2;
|
||||
}
|
||||
|
||||
hwnd = CreateWindowEx(
|
||||
WS_EX_CLIENTEDGE,
|
||||
WINDOW_CLASS,
|
||||
WINDOW_TITLE,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
|
||||
NULL, NULL, GetModuleHandle(NULL), NULL);
|
||||
|
||||
if(hwnd == NULL) {
|
||||
lua_pushboolean(L, 0);
|
||||
lua_pushstring(L, "Window creation failed");
|
||||
return 2;
|
||||
}
|
||||
|
||||
ShowWindow(hwnd, SW_SHOW);
|
||||
UpdateWindow(hwnd);
|
||||
|
||||
lua_pushboolean(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void winapigpu_init(lua_State* L) {
|
||||
struct luaL_Reg winlib[] = {
|
||||
{"open", l_open},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
luaL_openlib(L, "winapigpu", winlib, 0);
|
||||
}
|
||||
|
||||
int winapigpu_events() {
|
||||
MSG Msg;
|
||||
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
|
||||
TranslateMessage(&Msg);
|
||||
DispatchMessage(&Msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
@ -19,6 +19,11 @@ local function tryFb()
|
||||
return false
|
||||
end
|
||||
|
||||
local function tryWindows()
|
||||
loadModule("winapigpu")
|
||||
return modules.winapigpu.start() and true or false
|
||||
end
|
||||
|
||||
function gpudetect.run()
|
||||
local s = false
|
||||
if hasOpt("-t", "--text") then
|
||||
@ -32,6 +37,10 @@ function gpudetect.run()
|
||||
lprint("Falling back to text gpu")
|
||||
s = tryText()
|
||||
end
|
||||
if not s and winapigpu then
|
||||
lprint("Falling back to windows gpu")
|
||||
s = tryWindows()
|
||||
end
|
||||
end
|
||||
|
||||
return gpudetect
|
||||
|
11
src/lua/core/winapigpu.lua
Normal file
11
src/lua/core/winapigpu.lua
Normal file
@ -0,0 +1,11 @@
|
||||
local wingpu = {}
|
||||
|
||||
function wingpu.start()
|
||||
local s, reason = winapigpu.open()
|
||||
if not s then
|
||||
lprint("Couldn't open window: " .. tostring(reason))
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
return wingpu
|
Loading…
Reference in New Issue
Block a user