From 9b09b24a5cc3dfb0cee51e0d1876c9253894666a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 26 May 2014 17:44:09 +0800 Subject: [PATCH] Usermode/libaxwin4 - Implementation and debug --- Usermode/Libraries/libaxwin4.so_src/Makefile | 6 +-- .../include_exp/axwin4/axwin.h | 2 + Usermode/Libraries/libaxwin4.so_src/ipc.cpp | 8 ++- .../libaxwin4.so_src/ipc_acessipcpipe.cpp | 7 ++- .../libaxwin4.so_src/window_drawing.cpp | 49 +++++++++++++++++++ Usermode/Libraries/libaxwin4.so_src/wm.cpp | 37 ++++++++++++++ 6 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp diff --git a/Usermode/Libraries/libaxwin4.so_src/Makefile b/Usermode/Libraries/libaxwin4.so_src/Makefile index 31626671..c279a047 100644 --- a/Usermode/Libraries/libaxwin4.so_src/Makefile +++ b/Usermode/Libraries/libaxwin4.so_src/Makefile @@ -12,9 +12,8 @@ ASFLAGS += LDFLAGS += -soname libaxwin4.so -Map map.txt -lc -lc++ OBJ = main.o ipc.o ipc_acessipcpipe.o -OBJ += wm.o +OBJ += wm.o window_drawing.o OBJ += Common__serialisation.o -DEPFILES := $(OBJ:%.o=%.d) BIN = libaxwin4.so include ../Makefile.tpl @@ -22,7 +21,8 @@ include ../Makefile.tpl $(_OBJPREFIX)Common__%.o: $(AXWIN4DIR)/Common/%.cpp @echo [CXX] -o $@ @mkdir -p $(dir $@) - $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ -MQ $@ -MP -MD -MF $(@:%.o=%.dep) + $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ -MQ $@ -MP -MD -MF $(@:%=%.dep) + diff --git a/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h b/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h index fd545819..1bcf6f73 100644 --- a/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h +++ b/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h @@ -22,6 +22,8 @@ extern bool AxWin4_WaitEventQueueSelect(int nFDs, fd_set *rfds, fd_set *wfds, fd extern tAxWin4_Window *AxWin4_CreateWindow(const char *Name); extern void AxWin4_ShowWindow(tAxWin4_Window *Window); extern void AxWin4_SetTitle(tAxWin4_Window *Window, const char *Title); +extern void AxWin4_MoveWindow(tAxWin4_Window *Window, int X, int Y); +extern void AxWin4_ResizeWindow(tAxWin4_Window *Window, unsigned int W, unsigned int H); extern void AxWin4_DrawBitmap(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, void *Data); diff --git a/Usermode/Libraries/libaxwin4.so_src/ipc.cpp b/Usermode/Libraries/libaxwin4.so_src/ipc.cpp index c7a24555..10331fb3 100644 --- a/Usermode/Libraries/libaxwin4.so_src/ipc.cpp +++ b/Usermode/Libraries/libaxwin4.so_src/ipc.cpp @@ -20,16 +20,18 @@ IIPCChannel* gIPCChannel; extern "C" bool AxWin4_Connect(const char *URI) { + _SysDebug("AxWin4_Connect('%s')", URI); if( gIPCChannel ) { return false; } try { if( strncmp(URI, "ipcpipe://", 3+4+3) == 0 ) { - gIPCChannel = new CIPCChannel_AcessIPCPipe(URI); + gIPCChannel = new CIPCChannel_AcessIPCPipe(URI+3+4+3); } else { + _SysDebug("Unknown protocol"); return false; } } @@ -54,8 +56,10 @@ extern "C" bool AxWin4_WaitEventQueue(uint64_t Timeout) extern "C" bool AxWin4_WaitEventQueueSelect(int nFDs, fd_set *rfds, fd_set *wfds, fd_set *efds, uint64_t Timeout) { fd_set local_rfds; - if( !rfds ) + if( !rfds ) { + FD_ZERO(&local_rfds); rfds = &local_rfds; + } int64_t select_timeout = Timeout; int64_t *select_timeout_p = (Timeout ? &select_timeout : 0); diff --git a/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp b/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp index b7a509ce..2f879ff4 100644 --- a/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp +++ b/Usermode/Libraries/libaxwin4.so_src/ipc_acessipcpipe.cpp @@ -39,7 +39,12 @@ bool CIPCChannel_AcessIPCPipe::HandleSelect(const fd_set& fds) void CIPCChannel_AcessIPCPipe::Send(CSerialiser& message) { - // TODO: + const ::std::vector& serialised = message.Compact(); + if(serialised.size() > 0x1000 ) { + throw ::std::length_error("CIPCChannel_AcessIPCPipe::Send"); + } + _SysDebug("Send %i bytes", serialised.size()); + _SysWrite(m_fd, serialised.data(), serialised.size()); } diff --git a/Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp b/Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp new file mode 100644 index 00000000..df320ef7 --- /dev/null +++ b/Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp @@ -0,0 +1,49 @@ +/* + * AxWin4 Interface Library + * - By John Hodge (thePowersGang) + * + * window_drawing.cpp + * - Window drawing code + */ +#include +#include "include/common.hpp" +#include + +namespace AxWin { + +extern "C" void AxWin4_DrawBitmap(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, void *Data) +{ + // TODO: Split message up into blocks such that it can be dispatched + if( W > 128 ) + { + const uint32_t* data32 = static_cast(Data); + for( unsigned int row = 0; row < H; row ++ ) + { + CSerialiser message; + message.WriteU8(IPCMSG_PUSHDATA); + message.WriteU16(Window->m_id); + message.WriteU16(X); + message.WriteU16(Y+row); + message.WriteU16(W); + message.WriteU16(1); + message.WriteBuffer(W*4, data32); + ::AxWin::SendMessage(message); + data32 += W; + } + } + else + { + CSerialiser message; + message.WriteU8(IPCMSG_PUSHDATA); + message.WriteU16(Window->m_id); + message.WriteU16(X); + message.WriteU16(Y); + message.WriteU16(W); + message.WriteU16(H); + message.WriteBuffer(W*H*4, Data); + ::AxWin::SendMessage(message); + } +} + +}; // namespace AxWin + diff --git a/Usermode/Libraries/libaxwin4.so_src/wm.cpp b/Usermode/Libraries/libaxwin4.so_src/wm.cpp index 12c02c58..50712d48 100644 --- a/Usermode/Libraries/libaxwin4.so_src/wm.cpp +++ b/Usermode/Libraries/libaxwin4.so_src/wm.cpp @@ -16,25 +16,62 @@ extern "C" tAxWin4_Window *AxWin4_CreateWindow(const char *Name) // Allocate a window ID // Create window structure locally // Request creation of window + CSerialiser message; + message.WriteU8(IPCMSG_CREATEWIN); + message.WriteU16(0); + message.WriteString(Name); + ::AxWin::SendMessage(message); } extern "C" void AxWin4_ShowWindow(tAxWin4_Window *Window) { CSerialiser message; + message.WriteU8(IPCMSG_SETWINATTR); message.WriteU16(Window->m_id); message.WriteU16(IPC_WINATTR_SHOW); message.WriteU8(1); ::AxWin::SendMessage(message); } +extern "C" void AxWin4_MoveWindow(tAxWin4_Window *Window, int X, int Y) +{ + CSerialiser message; + message.WriteU8(IPCMSG_SETWINATTR); + message.WriteU16(Window->m_id); + message.WriteU16(IPC_WINATTR_POSITION); + message.WriteS16(X); + message.WriteS16(Y); + ::AxWin::SendMessage(message); +} +extern "C" void AxWin4_ResizeWindow(tAxWin4_Window *Window, unsigned int W, unsigned int H) +{ + CSerialiser message; + message.WriteU8(IPCMSG_SETWINATTR); + message.WriteU16(Window->m_id); + message.WriteU16(IPC_WINATTR_POSITION); + message.WriteU16(W); + message.WriteU16(H); + ::AxWin::SendMessage(message); +} + extern "C" void AxWin4_SetTitle(tAxWin4_Window *Window, const char *Title) { CSerialiser message; + message.WriteU8(IPCMSG_SETWINATTR); message.WriteU16(Window->m_id); message.WriteU16(IPC_WINATTR_TITLE); message.WriteString(Title); ::AxWin::SendMessage(message); } +extern "C" void *AxWin4_GetWindowBuffer(tAxWin4_Window *Window) +{ + //if( !Window->m_buffer ) + //{ + // // TODO: Support non-blocking operations + //} + return NULL; +} + }; // namespace AxWin -- 2.20.1