35 size_t SharedBuffer::m_NextId = 0;
37 Framebuffer::Framebuffer()
38 : m_pFramebuffer(0), m_FramebufferSize(0), m_Format(), m_Width(0),
39 m_Height(0), m_pScreen(0), m_pBackbuffer(0)
43 Framebuffer::~Framebuffer()
45 SDL_FreeSurface(m_pBackbuffer);
65 m_pScreen = SDL_SetVideoMode(
66 desiredW, desiredH, desiredBpp, SDL_DOUBLEBUF | SDL_SWSURFACE);
69 m_pBackbuffer = SDL_CreateRGBSurface(
70 SDL_DOUBLEBUF | SDL_SWSURFACE, desiredW, desiredH, 32, 0x00FF0000,
71 0x0000FF00, 0x000000FF, 0);
73 m_pFramebuffer = (
void *) m_pBackbuffer->pixels;
75 m_Width = m_pScreen->w;
76 m_Height = m_pScreen->h;
77 m_Format = CAIRO_FORMAT_RGB24;
85 SDL_BlitSurface(m_pBackbuffer, NULL, m_pScreen, NULL);
89 SharedBuffer::SharedBuffer(
size_t size)
90 : m_ShmName(), m_ShmFd(-1), m_pBuffer(0), m_Size(size)
92 size_t bufferId = m_NextId++;
94 memset(m_ShmName, 0,
sizeof m_ShmName);
95 sprintf(m_ShmName,
"wm%zd", bufferId);
97 m_ShmFd = shm_open(m_ShmName, O_RDWR | O_CREAT, 0777);
98 syslog(LOG_INFO,
"opening shm %s [fd=%d]", m_ShmName, m_ShmFd);
99 int r = ftruncate(m_ShmFd, size);
102 m_pBuffer = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, m_ShmFd, 0);
105 SharedBuffer::SharedBuffer(
size_t size,
void *handle)
106 : m_ShmName(), m_ShmFd(-1), m_pBuffer(0), m_Size(size)
109 memcpy(m_ShmName, &handle, 8);
111 m_ShmFd = shm_open(m_ShmName, O_RDWR, 0777);
112 syslog(LOG_INFO,
"opening client shm %s [fd=%d]", m_ShmName, m_ShmFd);
114 m_pBuffer = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, m_ShmFd, 0);
119 syslog(LOG_INFO,
"unmapping %zd bytes @%p", m_Size, m_pBuffer);
120 munmap(m_pBuffer, m_Size);
122 shm_unlink(m_ShmName);
128 memcpy(&v, m_ShmName, 8);
int enterMode(size_t desiredW, size_t desiredH, size_t desiredBpp)
void flush(size_t x, size_t y, size_t w, size_t h)