--- sourceforge.net/trunk/rdesktop/xwin.c 2004/03/03 10:46:35 620 +++ sourceforge.net/trunk/rdesktop/xwin.c 2004/11/03 13:56:52 795 @@ -43,8 +43,12 @@ static int g_x_socket; static Screen *g_screen; Window g_wnd; +extern uint32 g_embed_wnd; BOOL g_enable_compose = False; +BOOL g_Unobscured; /* used for screenblt */ static GC g_gc = NULL; +static GC g_create_bitmap_gc = NULL; +static GC g_create_glyph_gc = NULL; static Visual *g_visual; static int g_depth; static int g_bpp; @@ -56,6 +60,7 @@ static Atom g_protocol_atom, g_kill_atom; static BOOL g_focused; static BOOL g_mouse_in_wnd; +static BOOL g_arch_match = False; /* set to True if RGB XServer and little endian */ /* endianness */ static BOOL g_host_be; @@ -64,7 +69,7 @@ static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; /* software backing store */ -BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ +extern BOOL g_ownbackstore; static Pixmap g_backstore = 0; /* Moving in single app mode */ @@ -113,7 +118,7 @@ } /* colour maps */ -BOOL g_owncolmap = False; +extern BOOL g_owncolmap; static Colormap g_xcolmap; static uint32 *g_colmap = NULL; @@ -169,9 +174,9 @@ split_colour15(uint32 colour) { PixelColour rv; - rv.red = (colour & 0x7c00) >> 7; - rv.green = (colour & 0x03e0) >> 2; - rv.blue = (colour & 0x001f) << 3; + rv.red = ((colour >> 7) & 0xf8) | ((colour >> 12) & 0x7); + rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7); + rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7); return rv; } @@ -179,9 +184,9 @@ split_colour16(uint32 colour) { PixelColour rv; - rv.red = (colour & 0xf800) >> 8; - rv.green = (colour & 0x07e0) >> 3; - rv.blue = (colour & 0x001f) << 3; + rv.red = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7); + rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3); + rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7); return rv; } @@ -227,6 +232,32 @@ return make_colour(pc); } +/* indent is confused by UNROLL8 */ +/* *INDENT-OFF* */ + +/* repeat and unroll, similar to bitmap.c */ +/* potentialy any of the following translate */ +/* functions can use repeat but just doing */ +/* the most common ones */ + +#define UNROLL8(stm) { stm stm stm stm stm stm stm stm } +/* 2 byte output repeat */ +#define REPEAT2(stm) \ +{ \ + while (out <= end - 8 * 2) \ + UNROLL8(stm) \ + while (out < end) \ + { stm } \ +} +/* 4 byte output repeat */ +#define REPEAT4(stm) \ +{ \ + while (out <= end - 8 * 4) \ + UNROLL8(stm) \ + while (out < end) \ + { stm } \ +} + static void translate8to8(uint8 * data, uint8 * out, uint8 * end) { @@ -239,17 +270,28 @@ { uint16 value; - while (out < end) + if (g_arch_match) { - value = (uint16) g_colmap[*(data++)]; - - if (g_xserver_be) + REPEAT2 + ( + *((uint16 *) out) = g_colmap[*(data++)]; + out += 2; + ) + } + else if (g_xserver_be) + { + while (out < end) { + value = (uint16) g_colmap[*(data++)]; *(out++) = value >> 8; *(out++) = value; } - else + } + else + { + while (out < end) { + value = (uint16) g_colmap[*(data++)]; *(out++) = value; *(out++) = value >> 8; } @@ -262,18 +304,21 @@ { uint32 value; - while (out < end) + if (g_xserver_be) { - value = g_colmap[*(data++)]; - - if (g_xserver_be) + while (out < end) { + value = g_colmap[*(data++)]; *(out++) = value >> 16; *(out++) = value >> 8; *(out++) = value; } - else + } + else + { + while (out < end) { + value = g_colmap[*(data++)]; *(out++) = value; *(out++) = value >> 8; *(out++) = value >> 16; @@ -286,19 +331,30 @@ { uint32 value; - while (out < end) + if (g_arch_match) { - value = g_colmap[*(data++)]; - - if (g_xserver_be) + REPEAT4 + ( + *((uint32 *) out) = g_colmap[*(data++)]; + out += 4; + ) + } + else if (g_xserver_be) + { + while (out < end) { + value = g_colmap[*(data++)]; *(out++) = value >> 24; *(out++) = value >> 16; *(out++) = value >> 8; *(out++) = value; } - else + } + else + { + while (out < end) { + value = g_colmap[*(data++)]; *(out++) = value; *(out++) = value >> 8; *(out++) = value >> 16; @@ -307,6 +363,8 @@ } } +/* *INDENT-ON* */ + static void translate15to16(uint16 * data, uint8 * out, uint8 * end) { @@ -587,9 +645,24 @@ static uint8 * translate_image(int width, int height, uint8 * data) { - int size = width * height * g_bpp / 8; - uint8 *out = (uint8 *) xmalloc(size); - uint8 *end = out + size; + int size; + uint8 *out; + uint8 *end; + + /* if server and xserver bpp match, */ + /* and arch(endian) matches, no need to translate */ + /* just return data */ + if (g_arch_match) + { + if (g_depth == 15 && g_server_bpp == 15) + return data; + if (g_depth == 16 && g_server_bpp == 16) + return data; + } + + size = width * height * (g_bpp / 8); + out = (uint8 *) xmalloc(size); + end = out + size; switch (g_server_bpp) { @@ -727,6 +800,10 @@ TrueColorVisual = True; } + test = 1; + g_host_be = !(BOOL) (*(uint8 *) (&test)); + g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); + if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) { /* we use a colourmap, so the default visual should do */ @@ -753,6 +830,11 @@ calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); + + /* if RGB video and averything is little endian */ + if (vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) + if (!g_xserver_be && !g_host_be) + g_arch_match = True; } pfm = XListPixmapFormats(g_display, &i); @@ -792,10 +874,6 @@ g_ownbackstore = True; } - test = 1; - g_host_be = !(BOOL) (*(uint8 *) (&test)); - g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); - /* * Determine desktop size */ @@ -868,7 +946,8 @@ ui_create_window(void) { uint8 null_pointer_mask[1] = { 0x80 }; - uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 }; + uint8 null_pointer_data[24] = { 0x00 }; + XSetWindowAttributes attribs; XClassHint *classhints; XSizeHints *sizehints; @@ -893,6 +972,9 @@ if (g_gc == NULL) g_gc = XCreateGC(g_display, g_wnd, 0, NULL); + if (g_create_bitmap_gc == NULL) + g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL); + if ((g_ownbackstore) && (g_backstore == 0)) { g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth); @@ -925,6 +1007,11 @@ XFree(sizehints); } + if (g_embed_wnd) + { + XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0); + } + input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | VisibilityChangeMask | FocusChangeMask; @@ -956,6 +1043,7 @@ XMaskEvent(g_display, VisibilityChangeMask, &xevent); } while (xevent.type != VisibilityNotify); + g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured; g_focused = False; g_mouse_in_wnd = False; @@ -973,6 +1061,39 @@ } void +ui_resize_window() +{ + XSizeHints *sizehints; + Pixmap bs; + + sizehints = XAllocSizeHints(); + if (sizehints) + { + sizehints->flags = PMinSize | PMaxSize; + sizehints->min_width = sizehints->max_width = g_width; + sizehints->min_height = sizehints->max_height = g_height; + XSetWMNormalHints(g_display, g_wnd, sizehints); + XFree(sizehints); + } + + if (!(g_fullscreen || g_embed_wnd)) + { + XResizeWindow(g_display, g_wnd, g_width, g_height); + } + + /* create new backstore pixmap */ + if (g_backstore != 0) + { + bs = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth); + XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); + XFillRectangle(g_display, bs, g_gc, 0, 0, g_width, g_height); + XCopyArea(g_display, g_backstore, bs, g_gc, 0, 0, g_width, g_height, 0, 0); + XFreePixmap(g_display, g_backstore); + g_backstore = bs; + } +} + +void ui_destroy_window(void) { if (g_IC != NULL) @@ -1033,6 +1154,9 @@ switch (xevent.type) { + case VisibilityNotify: + g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured; + break; case ClientMessage: /* the window manager told us to quit */ if ((xevent.xclient.message_type == g_protocol_atom) @@ -1311,12 +1435,9 @@ error("select: %s\n", strerror(errno)); case 0: - /* TODO: if tv.tv_sec just times out - * we will segfault. - * FIXME: - */ - //s_timeout = True; - //rdpdr_check_fds(&rfds, &wfds, (BOOL) True); + /* Abort serial read calls */ + if (s_timeout) + rdpdr_check_fds(&rfds, &wfds, (BOOL) True); continue; } @@ -1363,10 +1484,10 @@ image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, (char *) tdata, width, height, bitmap_pad, 0); - XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height); + XPutImage(g_display, bitmap, g_create_bitmap_gc, image, 0, 0, 0, 0, width, height); XFree(image); - if (!g_owncolmap) + if (tdata != data) xfree(tdata); return (HBITMAP) bitmap; } @@ -1405,7 +1526,7 @@ } XFree(image); - if (!g_owncolmap) + if (tdata != data) xfree(tdata); } @@ -1421,12 +1542,12 @@ XImage *image; Pixmap bitmap; int scanline; - GC gc; scanline = (width + 7) / 8; bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1); - gc = XCreateGC(g_display, bitmap, 0, NULL); + if (g_create_glyph_gc == 0) + g_create_glyph_gc = XCreateGC(g_display, bitmap, 0, NULL); image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data, width, height, 8, scanline); @@ -1434,10 +1555,9 @@ image->bitmap_bit_order = MSBFirst; XInitImage(image); - XPutImage(g_display, bitmap, gc, image, 0, 0, 0, 0, width, height); + XPutImage(g_display, bitmap, g_create_glyph_gc, image, 0, 0, 0, 0, width, height); XFree(image); - XFreeGC(g_display, gc); return (HGLYPH) bitmap; } @@ -1729,7 +1849,7 @@ { case 0: /* Solid */ SET_FOREGROUND(fgcolour); - FILL_RECTANGLE(x, y, cx, cy); + FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); break; case 2: /* Hatch */ @@ -1740,7 +1860,7 @@ XSetFillStyle(g_display, g_gc, FillOpaqueStippled); XSetStipple(g_display, g_gc, fill); XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); - FILL_RECTANGLE(x, y, cx, cy); + FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); XSetFillStyle(g_display, g_gc, FillSolid); XSetTSOrigin(g_display, g_gc, 0, 0); ui_destroy_glyph((HGLYPH) fill); @@ -1750,15 +1870,12 @@ for (i = 0; i != 8; i++) ipattern[7 - i] = brush->pattern[i]; fill = (Pixmap) ui_create_glyph(8, 8, ipattern); - SET_FOREGROUND(bgcolour); SET_BACKGROUND(fgcolour); XSetFillStyle(g_display, g_gc, FillOpaqueStippled); XSetStipple(g_display, g_gc, fill); XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); - - FILL_RECTANGLE(x, y, cx, cy); - + FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); XSetFillStyle(g_display, g_gc, FillSolid); XSetTSOrigin(g_display, g_gc, 0, 0); ui_destroy_glyph((HGLYPH) fill); @@ -1769,6 +1886,9 @@ } RESET_FUNCTION(opcode); + + if (g_ownbackstore) + XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); } void @@ -1779,8 +1899,18 @@ SET_FUNCTION(opcode); if (g_ownbackstore) { - XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); - XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y); + if (g_Unobscured) + { + XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); + XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, + y); + } + else + { + XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); + XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, + y); + } } else { @@ -2055,3 +2185,14 @@ XFree(image); } + +/* these do nothing here but are used in uiports */ +void +ui_begin_update(void) +{ +} + +void +ui_end_update(void) +{ +}