X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibaxwin4.so_src%2Fwm.cpp;h=7ce61e4b1bb70fd360255cfd1a28bd13c39b2b9c;hb=7cbd63bd08b7a25dece2589403e330751a8ce2ef;hp=50712d487648e8be877889db3df15744fde2928f;hpb=9b09b24a5cc3dfb0cee51e0d1876c9253894666a;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libaxwin4.so_src/wm.cpp b/Usermode/Libraries/libaxwin4.so_src/wm.cpp index 50712d48..7ce61e4b 100644 --- a/Usermode/Libraries/libaxwin4.so_src/wm.cpp +++ b/Usermode/Libraries/libaxwin4.so_src/wm.cpp @@ -8,28 +8,61 @@ #include #include "include/common.hpp" #include +#include +#include +#include namespace AxWin { +static const int MAX_WINDOW_ID = 16; +static ::std::mutex glWindowList; +static ::std::vector gWindowList; + extern "C" tAxWin4_Window *AxWin4_CreateWindow(const char *Name) { // Allocate a window ID + ::std::lock_guard lock(glWindowList); + int id = ::std::find(gWindowList.begin(), gWindowList.end(), nullptr) - gWindowList.end(); + if( id >= MAX_WINDOW_ID ) { + throw ::std::runtime_error("AxWin4_CreateWindow - Out of IDs (TODO: Better exception)"); + } + if( id == gWindowList.size() ) + { + gWindowList.push_back(nullptr); + } + // Create window structure locally + tAxWin4_Window *ret = new tAxWin4_Window(); + gWindowList[id] = ret; + ret->m_id = id; + ret->m_fd = -1; + ret->m_buffer = nullptr; // Request creation of window CSerialiser message; message.WriteU8(IPCMSG_CREATEWIN); - message.WriteU16(0); + message.WriteU16(ret->m_id); message.WriteString(Name); ::AxWin::SendMessage(message); + return ret; } -extern "C" void AxWin4_ShowWindow(tAxWin4_Window *Window) +extern "C" void AxWin4_ShowWindow(tAxWin4_Window *Window, bool Show) { CSerialiser message; message.WriteU8(IPCMSG_SETWINATTR); message.WriteU16(Window->m_id); message.WriteU16(IPC_WINATTR_SHOW); - message.WriteU8(1); + message.WriteU8( (Show ? 1 : 0) ); + ::AxWin::SendMessage(message); +} + +extern "C" void AxWin4_SetWindowFlags(tAxWin4_Window *Window, unsigned int Flags) +{ + CSerialiser message; + message.WriteU8(IPCMSG_SETWINATTR); + message.WriteU16(Window->m_id); + message.WriteU16(IPC_WINATTR_FLAGS); + message.WriteU8( Flags ); ::AxWin::SendMessage(message); } @@ -48,7 +81,7 @@ extern "C" void AxWin4_ResizeWindow(tAxWin4_Window *Window, unsigned int W, unsi CSerialiser message; message.WriteU8(IPCMSG_SETWINATTR); message.WriteU16(Window->m_id); - message.WriteU16(IPC_WINATTR_POSITION); + message.WriteU16(IPC_WINATTR_DIMENSIONS); message.WriteU16(W); message.WriteU16(H); ::AxWin::SendMessage(message); @@ -64,13 +97,47 @@ extern "C" void AxWin4_SetTitle(tAxWin4_Window *Window, const char *Title) ::AxWin::SendMessage(message); } +extern "C" void AxWin4_DamageRect(tAxWin4_Window *Window, unsigned int X, unsigned int Y, unsigned int W, unsigned int H) +{ + CSerialiser message; + message.WriteU8(IPCMSG_DAMAGERECT); + message.WriteU16(Window->m_id); + message.WriteU16(X); + message.WriteU16(Y); + message.WriteU16(W); + message.WriteU16(H); + ::AxWin::SendMessage(message); +} + extern "C" void *AxWin4_GetWindowBuffer(tAxWin4_Window *Window) { - //if( !Window->m_buffer ) - //{ - // // TODO: Support non-blocking operations - //} - return NULL; + if( Window->m_fd == -1 ) + { + CSerialiser req; + req.WriteU8(IPCMSG_GETWINBUF); + req.WriteU16(Window->m_id); + + CDeserialiser response = GetSyncReply(req, IPCMSG_GETWINBUF); + unsigned int rspwin = response.ReadU16(); + if( rspwin != Window->m_id ) + { + _SysDebug("AxWin4_GetWindowBuffer: GETWINBUF reply for different window (%u != %u)", rspwin, Window->m_id); + return NULL; + } + + uint64_t handle = response.ReadU64(); + Window->m_fd = _SysUnMarshalFD(handle); + + _SysDebug("AxWin4_GetWindowBuffer: %llx = %i", handle, Window->m_fd); + } + + if( !Window->m_buffer ) + { + size_t size = 640*480*4; + Window->m_buffer = _SysMMap(NULL, size, MMAP_PROT_WRITE, MMAP_MAP_SHARED, Window->m_fd, 0); + } + + return Window->m_buffer; } }; // namespace AxWin