xvfb: Adaptation to timer and framebuffer changes

This commit is contained in:
Norman Feske 2013-02-14 10:45:49 +01:00
parent 1ab0ae908b
commit 14b9589780
2 changed files with 18 additions and 18 deletions

View File

@ -13,6 +13,7 @@
/* Linux includes */ /* Linux includes */
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
@ -52,10 +53,9 @@ int config_force_top = 1;
static int xvfb_width, xvfb_height; static int xvfb_width, xvfb_height;
static Pixel *xvfb_addr; static Pixel *xvfb_addr;
static Framebuffer::Session *fb_session; static Framebuffer::Session *fb_session;
static int fb_width, fb_height; static Framebuffer::Mode fb_mode;
static Framebuffer::Session::Mode fb_mode; static Pixel *fb_addr;
static Pixel *fb_addr;
static Nitpicker::Session *nitpicker() static Nitpicker::Session *nitpicker()
@ -101,10 +101,10 @@ static bool read_config()
static inline long convert_from_big_endian(long x) static inline long convert_from_big_endian(long x)
{ {
char v[4] = { char v[4] = {
(x & 0xff000000) >> 24, (char)((x & 0xff000000) >> 24),
(x & 0x00ff0000) >> 16, (char)((x & 0x00ff0000) >> 16),
(x & 0x0000ff00) >> 8, (char)((x & 0x0000ff00) >> 8),
(x & 0x000000ff) >> 0, (char)((x & 0x000000ff) >> 0),
}; };
return *(long *)v; return *(long *)v;
} }
@ -134,19 +134,19 @@ static void *mmap_file(const char *file_name)
/** /**
* Flush part of the Xvfb screen to the Nitpicker session * Flush part of the Xvfb screen to the Nitpicker session
*/ */
static void flush(int x, int y, int width, int height) static void flush(int x, int y, int width, int height, Framebuffer::Mode const &mode)
{ {
/* clip arguments against framebuffer geometry */ /* clip arguments against framebuffer geometry */
if (x < 0) width += x, x = 0; if (x < 0) width += x, x = 0;
if (y < 0) height += y, y = 0; if (y < 0) height += y, y = 0;
if (width > fb_width - x) width = fb_width - x; if (width > mode.width() - x) width = mode.width() - x;
if (height > fb_height - y) height = fb_height - y; if (height > mode.height() - y) height = mode.height() - y;
if (width <= 0 || height <= 0) return; if (width <= 0 || height <= 0) return;
/* copy pixels from xvfb to the nitpicker buffer */ /* copy pixels from xvfb to the nitpicker buffer */
blit(xvfb_addr + x + xvfb_width*y, xvfb_width*sizeof(Pixel), blit(xvfb_addr + x + xvfb_width*y, xvfb_width*sizeof(Pixel),
fb_addr + x + fb_width*y, fb_width*sizeof(Pixel), fb_addr + x + mode.width()*y, mode.width()*sizeof(Pixel),
width*sizeof(Pixel), height); width*sizeof(Pixel), height);
/* refresh nitpicker views */ /* refresh nitpicker views */
@ -265,7 +265,7 @@ int main(int, char **)
static Input::Session_client input(nitpicker()->input_session()); static Input::Session_client input(nitpicker()->input_session());
fb_session = &fb; fb_session = &fb;
fb_addr = Genode::env()->rm_session()->attach(fb.dataspace()); fb_addr = Genode::env()->rm_session()->attach(fb.dataspace());
fb.info(&fb_width, &fb_height, &fb_mode); fb_mode = fb.mode();
XWDFileHeader *xwd = (XWDFileHeader *)mmap_file(config_xvfb_file_name); XWDFileHeader *xwd = (XWDFileHeader *)mmap_file(config_xvfb_file_name);
if (!xwd) return -1; if (!xwd) return -1;
@ -283,9 +283,9 @@ int main(int, char **)
xvfb_addr = (Pixel *)((long)xwd + convert_from_big_endian(xwd->header_size) xvfb_addr = (Pixel *)((long)xwd + convert_from_big_endian(xwd->header_size)
+ convert_from_big_endian(xwd->ncolors)*sizeof(XWDColor)); + convert_from_big_endian(xwd->ncolors)*sizeof(XWDColor));
if (xvfb_width != fb_width || xvfb_height != fb_height) { if (xvfb_width != fb_mode.width() || xvfb_height != fb_mode.height()) {
Genode::printf("Error: Xvfb mode must equal the Nitpicker screen mode of %dx%d\n", Genode::printf("Error: Xvfb mode must equal the Nitpicker screen mode of %dx%d\n",
fb_width, fb_height); fb_mode.width(), fb_mode.height());
return -3; return -3;
} }
@ -332,7 +332,7 @@ int main(int, char **)
if (pending_redraw.valid()) if (pending_redraw.valid())
flush(pending_redraw.x(), pending_redraw.y(), flush(pending_redraw.x(), pending_redraw.y(),
pending_redraw.w(), pending_redraw.h()); pending_redraw.w(), pending_redraw.h(), fb_mode);
timer.msleep(5); timer.msleep(5);
} }

View File

@ -1,6 +1,6 @@
TARGET = xvfb TARGET = xvfb
REQUIRES = linux x11 xtest xdamage REQUIRES = linux x11 xtest xdamage
SRC_CC = main.cc inject_input.cc SRC_CC = main.cc inject_input.cc
LIBS = env syscall blit xev_track lx_hybrid LIBS = env syscall blit xev_track lx_hybrid signal
EXT_OBJECTS += -lX11 -lXdamage /usr/lib/libXtst.so.6 EXT_OBJECTS += -lX11 -lXdamage /usr/lib/libXtst.so.6