X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Faxwin4_src%2FServer%2FCSurface.cpp;h=07d8bfb607395b6c616f4355746717e34578e493;hb=4d0188930e7d0e571db78d1d2e3c4d9b3f0fe8fb;hp=6d4b0907696d41c48ab9f0a98b9f5ac31210b444;hpb=74ccd1fff633643363e5c03785dba4ed9b44351e;p=tpg%2Facess2.git diff --git a/Usermode/Applications/axwin4_src/Server/CSurface.cpp b/Usermode/Applications/axwin4_src/Server/CSurface.cpp index 6d4b0907..07d8bfb6 100644 --- a/Usermode/Applications/axwin4_src/Server/CSurface.cpp +++ b/Usermode/Applications/axwin4_src/Server/CSurface.cpp @@ -9,11 +9,15 @@ #include #include #include +#include +#include namespace AxWin { CSurface::CSurface(int x, int y, unsigned int w, unsigned int h): - m_rect(x,y, w,h) + m_rect(x,y, w,h), + m_fd(-1), + m_data(0) { if( w > 0 && h > 0 ) { @@ -25,18 +29,39 @@ CSurface::~CSurface() { } -void CSurface::Resize(unsigned int W, unsigned int H) +uint64_t CSurface::GetSHMHandle() { - // Easy realloc - // TODO: Should I maintain window contents sanely? NOPE! + // 1. Free local buffer delete m_data; - m_data = new uint32_t[W * H]; + // 2. Allocate a copy in SHM + m_fd = _SysOpen("/Devices/shm/anon", OPENFLAG_WRITE|OPENFLAG_READ); + if(m_fd==-1) throw ::std::system_error(errno, ::std::system_category()); + size_t size = m_rect.m_w*m_rect.m_h*4; + _SysTruncate(m_fd, size); + // 3. mmap shm copy + m_data = static_cast( _SysMMap(nullptr, size, MMAP_PROT_WRITE, 0, m_fd, 0) ); + if(!m_data) throw ::std::system_error(errno, ::std::system_category()); + return _SysMarshalFD(m_fd); +} + +void CSurface::Resize(unsigned int W, unsigned int H) +{ + if( m_fd == -1 ) + { + // Easy realloc + // TODO: Should I maintain window contents sanely? NOPE! + delete m_data; + m_data = new uint32_t[W * H]; + } + else + { + //_SysIOCtl(m_fd, SHM_IOCTL_SETSIZE, W*H*4); + } m_rect.Resize(W, H); } void CSurface::DrawScanline(unsigned int row, unsigned int x_ofs, unsigned int w, const void* data) { - //_SysDebug("DrawScanline(%i,%i,%i,%p)", row, x_ofs, w, data); if( row >= m_rect.m_h ) throw ::std::out_of_range("CSurface::DrawScanline row"); if( x_ofs >= m_rect.m_w ) @@ -45,7 +70,8 @@ void CSurface::DrawScanline(unsigned int row, unsigned int x_ofs, unsigned int w if( w > m_rect.m_w ) throw ::std::out_of_range("CSurface::DrawScanline width"); - ::memcpy( &m_data[row*m_rect.m_w + x_ofs], data, w*4 ); + size_t ofs = row*m_rect.m_w + x_ofs; + ::memcpy( &m_data[ofs], data, w*4 ); } const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const