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];
32 uint64_t CSurface::GetSHMHandle()
34 // 1. Free local buffer
36 // 2. Allocate a copy in SHM
37 m_fd = _SysOpen("/Devices/shm/anon", OPENFLAG_WRITE|OPENFLAG_READ);
38 if(m_fd==-1) throw ::std::system_error(errno, ::std::system_category());
39 size_t size = m_rect.m_w*m_rect.m_h*4;
40 _SysTruncate(m_fd, size);
42 m_data = static_cast<uint32_t*>( _SysMMap(nullptr, size, MMAP_PROT_WRITE, 0, m_fd, 0) );
43 if(!m_data) throw ::std::system_error(errno, ::std::system_category());
44 return _SysMarshalFD(m_fd);
47 void CSurface::Resize(unsigned int W, unsigned int H)
52 // TODO: Should I maintain window contents sanely? NOPE!
54 m_data = new uint32_t[W * H];
58 //_SysIOCtl(m_fd, SHM_IOCTL_SETSIZE, W*H*4);
63 void CSurface::DrawScanline(unsigned int row, unsigned int x_ofs, unsigned int w, const void* data)
65 if( row >= m_rect.m_h )
66 throw ::std::out_of_range("CSurface::DrawScanline row");
67 if( x_ofs >= m_rect.m_w )
68 throw ::std::out_of_range("CSurface::DrawScanline x_ofs");
71 throw ::std::out_of_range("CSurface::DrawScanline width");
73 size_t ofs = row*m_rect.m_w + x_ofs;
74 ::memcpy( &m_data[ofs], data, w*4 );
77 const uint32_t* CSurface::GetScanline(unsigned int row, unsigned int x_ofs) const
79 if( row >= m_rect.m_h )
80 throw ::std::out_of_range("CSurface::GetScanline row");
81 if( x_ofs >= m_rect.m_w )
82 throw ::std::out_of_range("CSurface::GetScanline x_ofs");
84 return &m_data[row * m_rect.m_w + x_ofs];