3 * - By John Hodge (thePowersGang)
8 #include <CSurface.hpp>
12 #include <system_error>
17 CSurface::CSurface(int x, int y, unsigned int w, unsigned int h):
24 m_data = new uint32_t[w * h];
34 size_t size = m_rect.m_w*m_rect.m_h*4;
35 _SysMUnMap(m_data, size);
39 uint64_t CSurface::GetSHMHandle()
41 size_t size = m_rect.m_w*m_rect.m_h*4;
44 // 2. Allocate a copy in SHM
45 m_fd = _SysOpen("/Devices/shm/anon", OPENFLAG_WRITE|OPENFLAG_READ);
47 _SysDebug("GetSHMHandle: Unable to open anon SHM");
50 // 1. Free local buffer
52 _SysTruncate(m_fd, size);
56 _SysMUnMap(m_data, size);
59 m_data = static_cast<uint32_t*>( _SysMMap(nullptr, size, MMAP_PROT_WRITE, 0, m_fd, 0) );
60 if(!m_data) throw ::std::system_error(errno, ::std::system_category());
62 return _SysMarshalFD(m_fd);
65 void CSurface::Resize(unsigned int W, unsigned int H)
70 // TODO: Should I maintain window contents sanely? NOPE!
72 m_data = new uint32_t[W * H];
76 //_SysIOCtl(m_fd, SHM_IOCTL_SETSIZE, W*H*4);
81 void CSurface::DrawScanline(unsigned int row, unsigned int x_ofs, unsigned int w, const void* data)
83 if( row >= m_rect.m_h )
84 throw ::std::out_of_range("CSurface::DrawScanline row");
85 if( x_ofs >= m_rect.m_w )
86 throw ::std::out_of_range("CSurface::DrawScanline x_ofs");
89 throw ::std::out_of_range("CSurface::DrawScanline width");
91 size_t ofs = row*m_rect.m_w + x_ofs;
92 ::memcpy( &m_data[ofs], data, w*4 );
95 const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const
97 if( row >= m_rect.m_h )
98 throw ::std::out_of_range("CSurface::GetScanline row");
99 if( x_ofs >= m_rect.m_w )
100 throw ::std::out_of_range("CSurface::GetScanline x_ofs");
102 return &m_data[row * m_rect.m_w + x_ofs];
106 }; // namespace AxWin