/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/rdesktop/xwin.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/branches/seamlessrdp-branch/rdesktop/xwin.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 619 by astrand, Wed Mar 3 10:41:53 2004 UTC revision 821 by jdmeijer, Mon Feb 28 01:15:45 2005 UTC
# Line 30  Line 30 
30    
31  extern int g_width;  extern int g_width;
32  extern int g_height;  extern int g_height;
33    extern int g_xpos;
34    extern int g_ypos;
35  extern BOOL g_sendmotion;  extern BOOL g_sendmotion;
36  extern BOOL g_fullscreen;  extern BOOL g_fullscreen;
37  extern BOOL g_grab_keyboard;  extern BOOL g_grab_keyboard;
# Line 43  Time g_last_gesturetime; Line 45  Time g_last_gesturetime;
45  static int g_x_socket;  static int g_x_socket;
46  static Screen *g_screen;  static Screen *g_screen;
47  Window g_wnd;  Window g_wnd;
48    extern uint32 g_embed_wnd;
49  BOOL g_enable_compose = False;  BOOL g_enable_compose = False;
50    BOOL g_Unobscured;              /* used for screenblt */
51  static GC g_gc = NULL;  static GC g_gc = NULL;
52    static GC g_create_bitmap_gc = NULL;
53    static GC g_create_glyph_gc = NULL;
54  static Visual *g_visual;  static Visual *g_visual;
55  static int g_depth;  static int g_depth;
56  static int g_bpp;  static int g_bpp;
# Line 56  static HCURSOR g_null_cursor = NULL; Line 62  static HCURSOR g_null_cursor = NULL;
62  static Atom g_protocol_atom, g_kill_atom;  static Atom g_protocol_atom, g_kill_atom;
63  static BOOL g_focused;  static BOOL g_focused;
64  static BOOL g_mouse_in_wnd;  static BOOL g_mouse_in_wnd;
65    static BOOL g_arch_match = False;       /* set to True if RGB XServer and little endian */
66    
67  /* endianness */  /* endianness */
68  static BOOL g_host_be;  static BOOL g_host_be;
# Line 64  static int g_red_shift_r, g_blue_shift_r Line 71  static int g_red_shift_r, g_blue_shift_r
71  static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;  static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
72    
73  /* software backing store */  /* software backing store */
74  BOOL g_ownbackstore = True;     /* We can't rely on external BackingStore */  extern BOOL g_ownbackstore;
75  static Pixmap g_backstore = 0;  static Pixmap g_backstore = 0;
76    
77  /* Moving in single app mode */  /* Moving in single app mode */
# Line 113  PixelColour; Line 120  PixelColour;
120  }  }
121    
122  /* colour maps */  /* colour maps */
123  BOOL g_owncolmap = False;  extern BOOL g_owncolmap;
124  static Colormap g_xcolmap;  static Colormap g_xcolmap;
125  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
126    
# Line 165  mwm_hide_decorations(void) Line 172  mwm_hide_decorations(void)
172                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);                          (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
173  }  }
174    
175  static PixelColour  #define SPLITCOLOUR15(colour, rv) \
176  split_colour15(uint32 colour)  { \
177  {          rv.red = ((colour >> 7) & 0xf8) | ((colour >> 12) & 0x7); \
178          PixelColour rv;          rv.green = ((colour >> 2) & 0xf8) | ((colour >> 8) & 0x7); \
179          rv.red = (colour & 0x7c00) >> 7;          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7); \
         rv.green = (colour & 0x03e0) >> 2;  
         rv.blue = (colour & 0x001f) << 3;  
         return rv;  
 }  
   
 static PixelColour  
 split_colour16(uint32 colour)  
 {  
         PixelColour rv;  
         rv.red = (colour & 0xf800) >> 8;  
         rv.green = (colour & 0x07e0) >> 3;  
         rv.blue = (colour & 0x001f) << 3;  
         return rv;  
 }  
   
 static PixelColour  
 split_colour24(uint32 colour)  
 {  
         PixelColour rv;  
         rv.blue = (colour & 0xff0000) >> 16;  
         rv.green = (colour & 0x00ff00) >> 8;  
         rv.red = (colour & 0x0000ff);  
         return rv;  
180  }  }
181    
182  static uint32  #define SPLITCOLOUR16(colour, rv) \
183  make_colour(PixelColour pc)  { \
184  {          rv.red = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7); \
185          return (((pc.red >> g_red_shift_r) << g_red_shift_l)          rv.green = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3); \
186                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)          rv.blue = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7); \
187                  | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l));  } \
188    
189    #define SPLITCOLOUR24(colour, rv) \
190    { \
191            rv.blue = (colour & 0xff0000) >> 16; \
192            rv.green = (colour & 0x00ff00) >> 8; \
193            rv.red = (colour & 0x0000ff); \
194  }  }
195    
196    #define MAKECOLOUR(pc) \
197            ((pc.red >> g_red_shift_r) << g_red_shift_l) \
198                    | ((pc.green >> g_green_shift_r) << g_green_shift_l) \
199                    | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l) \
200    
201  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
202  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }  #define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); }
203  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \  #define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \
204                          x = (x << 16) | (x >> 16); }                          x = (x << 16) | (x >> 16); }
205    
206    #define BOUT16(o, x) { *(o++) = x >> 8; *(o++) = x; }
207    #define BOUT24(o, x) { *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }
208    #define BOUT32(o, x) { *(o++) = x >> 24; *(o++) = x >> 16; *(o++) = x >> 8; *(o++) = x; }
209    #define LOUT16(o, x) { *(o++) = x; *(o++) = x >> 8; }
210    #define LOUT24(o, x) { *(o++) = x; *(o++) = x >> 8; *(o++) = x >> 16; }
211    #define LOUT32(o, x) { *(o++) = x; *(o++) = x >> 8; *(o++) = x >> 16; *(o++) = x >> 24; }
212    
213  static uint32  static uint32
214  translate_colour(uint32 colour)  translate_colour(uint32 colour)
215  {  {
# Line 215  translate_colour(uint32 colour) Line 217  translate_colour(uint32 colour)
217          switch (g_server_bpp)          switch (g_server_bpp)
218          {          {
219                  case 15:                  case 15:
220                          pc = split_colour15(colour);                          SPLITCOLOUR15(colour, pc);
221                          break;                          break;
222                  case 16:                  case 16:
223                          pc = split_colour16(colour);                          SPLITCOLOUR16(colour, pc);
224                          break;                          break;
225                  case 24:                  case 24:
226                          pc = split_colour24(colour);                          SPLITCOLOUR24(colour, pc);
227                          break;                          break;
228          }          }
229          return make_colour(pc);          return MAKECOLOUR(pc);
230  }  }
231    
232    /* indent is confused by UNROLL8 */
233    /* *INDENT-OFF* */
234    
235    /* repeat and unroll, similar to bitmap.c */
236    /* potentialy any of the following translate */
237    /* functions can use repeat but just doing */
238    /* the most common ones */
239    
240    #define UNROLL8(stm) { stm stm stm stm stm stm stm stm }
241    /* 2 byte output repeat */
242    #define REPEAT2(stm) \
243    { \
244            while (out <= end - 8 * 2) \
245                    UNROLL8(stm) \
246            while (out < end) \
247                    { stm } \
248    }
249    /* 3 byte output repeat */
250    #define REPEAT3(stm) \
251    { \
252            while (out <= end - 8 * 3) \
253                    UNROLL8(stm) \
254            while (out < end) \
255                    { stm } \
256    }
257    /* 4 byte output repeat */
258    #define REPEAT4(stm) \
259    { \
260            while (out <= end - 8 * 4) \
261                    UNROLL8(stm) \
262            while (out < end) \
263                    { stm } \
264    }
265    /* *INDENT-ON* */
266    
267  static void  static void
268  translate8to8(uint8 * data, uint8 * out, uint8 * end)  translate8to8(const uint8 * data, uint8 * out, uint8 * end)
269  {  {
270          while (out < end)          while (out < end)
271                  *(out++) = (uint8) g_colmap[*(data++)];                  *(out++) = (uint8) g_colmap[*(data++)];
272  }  }
273    
274  static void  static void
275  translate8to16(uint8 * data, uint8 * out, uint8 * end)  translate8to16(const uint8 * data, uint8 * out, uint8 * end)
276  {  {
277          uint16 value;          uint16 value;
278    
279          while (out < end)          if (g_arch_match)
280          {          {
281                  value = (uint16) g_colmap[*(data++)];                  /* *INDENT-OFF* */
282                    REPEAT2
283                  if (g_xserver_be)                  (
284                            *((uint16 *) out) = g_colmap[*(data++)];
285                            out += 2;
286                    )
287                    /* *INDENT-ON* */
288            }
289            else if (g_xserver_be)
290            {
291                    while (out < end)
292                  {                  {
293                          *(out++) = value >> 8;                          value = (uint16) g_colmap[*(data++)];
294                          *(out++) = value;                          BOUT16(out, value);
295                  }                  }
296                  else          }
297            else
298            {
299                    while (out < end)
300                  {                  {
301                          *(out++) = value;                          value = (uint16) g_colmap[*(data++)];
302                          *(out++) = value >> 8;                          LOUT16(out, value);
303                  }                  }
304          }          }
305  }  }
306    
307  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
308  static void  static void
309  translate8to24(uint8 * data, uint8 * out, uint8 * end)  translate8to24(const uint8 * data, uint8 * out, uint8 * end)
310  {  {
311          uint32 value;          uint32 value;
312    
313          while (out < end)          if (g_xserver_be)
314          {          {
315                  value = g_colmap[*(data++)];                  while (out < end)
   
                 if (g_xserver_be)  
316                  {                  {
317                          *(out++) = value >> 16;                          value = g_colmap[*(data++)];
318                          *(out++) = value >> 8;                          BOUT24(out, value);
                         *(out++) = value;  
319                  }                  }
320                  else          }
321            else
322            {
323                    while (out < end)
324                  {                  {
325                          *(out++) = value;                          value = g_colmap[*(data++)];
326                          *(out++) = value >> 8;                          LOUT24(out, value);
                         *(out++) = value >> 16;  
327                  }                  }
328          }          }
329  }  }
330    
331  static void  static void
332  translate8to32(uint8 * data, uint8 * out, uint8 * end)  translate8to32(const uint8 * data, uint8 * out, uint8 * end)
333  {  {
334          uint32 value;          uint32 value;
335    
336          while (out < end)          if (g_arch_match)
337          {          {
338                  value = g_colmap[*(data++)];                  /* *INDENT-OFF* */
339                    REPEAT4
340                  if (g_xserver_be)                  (
341                            *((uint32 *) out) = g_colmap[*(data++)];
342                            out += 4;
343                    )
344                    /* *INDENT-ON* */
345            }
346            else if (g_xserver_be)
347            {
348                    while (out < end)
349                  {                  {
350                          *(out++) = value >> 24;                          value = g_colmap[*(data++)];
351                          *(out++) = value >> 16;                          BOUT32(out, value);
                         *(out++) = value >> 8;  
                         *(out++) = value;  
352                  }                  }
353                  else          }
354            else
355            {
356                    while (out < end)
357                  {                  {
358                          *(out++) = value;                          value = g_colmap[*(data++)];
359                          *(out++) = value >> 8;                          LOUT32(out, value);
                         *(out++) = value >> 16;  
                         *(out++) = value >> 24;  
360                  }                  }
361          }          }
362  }  }
363    
364  static void  static void
365  translate15to16(uint16 * data, uint8 * out, uint8 * end)  translate15to16(const uint16 * data, uint8 * out, uint8 * end)
366  {  {
367          uint16 pixel;          uint16 pixel;
368          uint16 value;          uint16 value;
369            PixelColour pc;
370    
371          while (out < end)          if (g_xserver_be)
372          {          {
373                  pixel = *(data++);                  while (out < end)
   
                 if (g_host_be)  
374                  {                  {
375                          BSWAP16(pixel);                          pixel = *(data++);
376                  }                          if (g_host_be)
377                            {
378                  value = make_colour(split_colour15(pixel));                                  BSWAP16(pixel);
379                            }
380                  if (g_xserver_be)                          SPLITCOLOUR15(pixel, pc);
381                  {                          value = MAKECOLOUR(pc);
382                          *(out++) = value >> 8;                          BOUT16(out, value);
                         *(out++) = value;  
383                  }                  }
384                  else          }
385            else
386            {
387                    while (out < end)
388                  {                  {
389                          *(out++) = value;                          pixel = *(data++);
390                          *(out++) = value >> 8;                          if (g_host_be)
391                            {
392                                    BSWAP16(pixel);
393                            }
394                            SPLITCOLOUR15(pixel, pc);
395                            value = MAKECOLOUR(pc);
396                            LOUT16(out, value);
397                  }                  }
398          }          }
399  }  }
400    
401  static void  static void
402  translate15to24(uint16 * data, uint8 * out, uint8 * end)  translate15to24(const uint16 * data, uint8 * out, uint8 * end)
403  {  {
404          uint32 value;          uint32 value;
405          uint16 pixel;          uint16 pixel;
406            PixelColour pc;
407    
408          while (out < end)          if (g_arch_match)
409          {          {
410                  pixel = *(data++);                  /* *INDENT-OFF* */
411                    REPEAT3
412                  if (g_host_be)                  (
413                  {                          pixel = *(data++);
414                          BSWAP16(pixel);                          SPLITCOLOUR15(pixel, pc);
415                  }                          *(out++) = pc.blue;
416                            *(out++) = pc.green;
417                  value = make_colour(split_colour15(pixel));                          *(out++) = pc.red;
418                  if (g_xserver_be)                  )
419                    /* *INDENT-ON* */
420            }
421            else if (g_xserver_be)
422            {
423                    while (out < end)
424                  {                  {
425                          *(out++) = value >> 16;                          pixel = *(data++);
426                          *(out++) = value >> 8;                          if (g_host_be)
427                          *(out++) = value;                          {
428                                    BSWAP16(pixel);
429                            }
430                            SPLITCOLOUR15(pixel, pc);
431                            value = MAKECOLOUR(pc);
432                            BOUT24(out, value);
433                  }                  }
434                  else          }
435            else
436            {
437                    while (out < end)
438                  {                  {
439                          *(out++) = value;                          pixel = *(data++);
440                          *(out++) = value >> 8;                          if (g_host_be)
441                          *(out++) = value >> 16;                          {
442                                    BSWAP16(pixel);
443                            }
444                            SPLITCOLOUR15(pixel, pc);
445                            value = MAKECOLOUR(pc);
446                            LOUT24(out, value);
447                  }                  }
448          }          }
449  }  }
450    
451  static void  static void
452  translate15to32(uint16 * data, uint8 * out, uint8 * end)  translate15to32(const uint16 * data, uint8 * out, uint8 * end)
453  {  {
454          uint16 pixel;          uint16 pixel;
455          uint32 value;          uint32 value;
456            PixelColour pc;
457    
458          while (out < end)          if (g_arch_match)
459          {          {
460                  pixel = *(data++);                  /* *INDENT-OFF* */
461                    REPEAT4
462                  if (g_host_be)                  (
463                  {                          pixel = *(data++);
464                          BSWAP16(pixel);                          SPLITCOLOUR15(pixel, pc);
465                  }                          *(out++) = pc.blue;
466                            *(out++) = pc.green;
467                  value = make_colour(split_colour15(pixel));                          *(out++) = pc.red;
468                            *(out++) = 0;
469                  if (g_xserver_be)                  )
470                    /* *INDENT-ON* */
471            }
472            else if (g_xserver_be)
473            {
474                    while (out < end)
475                  {                  {
476                          *(out++) = value >> 24;                          pixel = *(data++);
477                          *(out++) = value >> 16;                          if (g_host_be)
478                          *(out++) = value >> 8;                          {
479                          *(out++) = value;                                  BSWAP16(pixel);
480                            }
481                            SPLITCOLOUR15(pixel, pc);
482                            value = MAKECOLOUR(pc);
483                            BOUT32(out, value);
484                  }                  }
485                  else          }
486            else
487            {
488                    while (out < end)
489                  {                  {
490                          *(out++) = value;                          pixel = *(data++);
491                          *(out++) = value >> 8;                          if (g_host_be)
492                          *(out++) = value >> 16;                          {
493                          *(out++) = value >> 24;                                  BSWAP16(pixel);
494                            }
495                            SPLITCOLOUR15(pixel, pc);
496                            value = MAKECOLOUR(pc);
497                            LOUT32(out, value);
498                  }                  }
499          }          }
500  }  }
501    
502  static void  static void
503  translate16to16(uint16 * data, uint8 * out, uint8 * end)  translate16to16(const uint16 * data, uint8 * out, uint8 * end)
504  {  {
505          uint16 pixel;          uint16 pixel;
506          uint16 value;          uint16 value;
507            PixelColour pc;
508    
509          while (out < end)          if (g_xserver_be)
510          {          {
                 pixel = *(data++);  
   
511                  if (g_host_be)                  if (g_host_be)
512                  {                  {
513                          BSWAP16(pixel);                          while (out < end)
514                            {
515                                    pixel = *(data++);
516                                    BSWAP16(pixel);
517                                    SPLITCOLOUR16(pixel, pc);
518                                    value = MAKECOLOUR(pc);
519                                    BOUT16(out, value);
520                            }
521                  }                  }
522                    else
523                  value = make_colour(split_colour16(pixel));                  {
524                            while (out < end)
525                  if (g_xserver_be)                          {
526                                    pixel = *(data++);
527                                    SPLITCOLOUR16(pixel, pc);
528                                    value = MAKECOLOUR(pc);
529                                    BOUT16(out, value);
530                            }
531                    }
532            }
533            else
534            {
535                    if (g_host_be)
536                  {                  {
537                          *(out++) = value >> 8;                          while (out < end)
538                          *(out++) = value;                          {
539                                    pixel = *(data++);
540                                    BSWAP16(pixel);
541                                    SPLITCOLOUR16(pixel, pc);
542                                    value = MAKECOLOUR(pc);
543                                    LOUT16(out, value);
544                            }
545                  }                  }
546                  else                  else
547                  {                  {
548                          *(out++) = value;                          while (out < end)
549                          *(out++) = value >> 8;                          {
550                                    pixel = *(data++);
551                                    SPLITCOLOUR16(pixel, pc);
552                                    value = MAKECOLOUR(pc);
553                                    LOUT16(out, value);
554                            }
555                  }                  }
556          }          }
557  }  }
558    
559  static void  static void
560  translate16to24(uint16 * data, uint8 * out, uint8 * end)  translate16to24(const uint16 * data, uint8 * out, uint8 * end)
561  {  {
562          uint32 value;          uint32 value;
563          uint16 pixel;          uint16 pixel;
564            PixelColour pc;
565    
566          while (out < end)          if (g_arch_match)
567            {
568                    /* *INDENT-OFF* */
569                    REPEAT3
570                    (
571                            pixel = *(data++);
572                            SPLITCOLOUR16(pixel, pc);
573                            *(out++) = pc.blue;
574                            *(out++) = pc.green;
575                            *(out++) = pc.red;
576                    )
577                    /* *INDENT-ON* */
578            }
579            else if (g_xserver_be)
580          {          {
                 pixel = *(data++);  
   
581                  if (g_host_be)                  if (g_host_be)
582                  {                  {
583                          BSWAP16(pixel);                          while (out < end)
584                            {
585                                    pixel = *(data++);
586                                    BSWAP16(pixel);
587                                    SPLITCOLOUR16(pixel, pc);
588                                    value = MAKECOLOUR(pc);
589                                    BOUT24(out, value);
590                            }
591                  }                  }
592                    else
593                  value = make_colour(split_colour16(pixel));                  {
594                            while (out < end)
595                  if (g_xserver_be)                          {
596                                    pixel = *(data++);
597                                    SPLITCOLOUR16(pixel, pc);
598                                    value = MAKECOLOUR(pc);
599                                    BOUT24(out, value);
600                            }
601                    }
602            }
603            else
604            {
605                    if (g_host_be)
606                  {                  {
607                          *(out++) = value >> 16;                          while (out < end)
608                          *(out++) = value >> 8;                          {
609                          *(out++) = value;                                  pixel = *(data++);
610                                    BSWAP16(pixel);
611                                    SPLITCOLOUR16(pixel, pc);
612                                    value = MAKECOLOUR(pc);
613                                    LOUT24(out, value);
614                            }
615                  }                  }
616                  else                  else
617                  {                  {
618                          *(out++) = value;                          while (out < end)
619                          *(out++) = value >> 8;                          {
620                          *(out++) = value >> 16;                                  pixel = *(data++);
621                                    SPLITCOLOUR16(pixel, pc);
622                                    value = MAKECOLOUR(pc);
623                                    LOUT24(out, value);
624                            }
625                  }                  }
626          }          }
627  }  }
628    
629  static void  static void
630  translate16to32(uint16 * data, uint8 * out, uint8 * end)  translate16to32(const uint16 * data, uint8 * out, uint8 * end)
631  {  {
632          uint16 pixel;          uint16 pixel;
633          uint32 value;          uint32 value;
634            PixelColour pc;
635    
636          while (out < end)          if (g_arch_match)
637            {
638                    /* *INDENT-OFF* */
639                    REPEAT4
640                    (
641                            pixel = *(data++);
642                            SPLITCOLOUR16(pixel, pc);
643                            *(out++) = pc.blue;
644                            *(out++) = pc.green;
645                            *(out++) = pc.red;
646                            *(out++) = 0;
647                    )
648                    /* *INDENT-ON* */
649            }
650            else if (g_xserver_be)
651          {          {
                 pixel = *(data++);  
   
652                  if (g_host_be)                  if (g_host_be)
653                  {                  {
654                          BSWAP16(pixel);                          while (out < end)
655                            {
656                                    pixel = *(data++);
657                                    BSWAP16(pixel);
658                                    SPLITCOLOUR16(pixel, pc);
659                                    value = MAKECOLOUR(pc);
660                                    BOUT32(out, value);
661                            }
662                  }                  }
663                    else
664                  value = make_colour(split_colour16(pixel));                  {
665                            {
666                  if (g_xserver_be)                                  pixel = *(data++);
667                                    SPLITCOLOUR16(pixel, pc);
668                                    value = MAKECOLOUR(pc);
669                                    BOUT32(out, value);
670                            }
671                    }
672            }
673            else
674            {
675                    if (g_host_be)
676                  {                  {
677                          *(out++) = value >> 24;                          while (out < end)
678                          *(out++) = value >> 16;                          {
679                          *(out++) = value >> 8;                                  pixel = *(data++);
680                          *(out++) = value;                                  BSWAP16(pixel);
681                                    SPLITCOLOUR16(pixel, pc);
682                                    value = MAKECOLOUR(pc);
683                                    LOUT32(out, value);
684                            }
685                  }                  }
686                  else                  else
687                  {                  {
688                          *(out++) = value;                          while (out < end)
689                          *(out++) = value >> 8;                          {
690                          *(out++) = value >> 16;                                  pixel = *(data++);
691                          *(out++) = value >> 24;                                  SPLITCOLOUR16(pixel, pc);
692                                    value = MAKECOLOUR(pc);
693                                    LOUT32(out, value);
694                            }
695                  }                  }
696          }          }
697  }  }
698    
699  static void  static void
700  translate24to16(uint8 * data, uint8 * out, uint8 * end)  translate24to16(const uint8 * data, uint8 * out, uint8 * end)
701  {  {
702          uint32 pixel = 0;          uint32 pixel = 0;
703          uint16 value;          uint16 value;
704            PixelColour pc;
705    
706          while (out < end)          while (out < end)
707          {          {
708                  pixel = *(data++) << 16;                  pixel = *(data++) << 16;
709                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
710                  pixel |= *(data++);                  pixel |= *(data++);
711                    SPLITCOLOUR24(pixel, pc);
712                  value = (uint16) make_colour(split_colour24(pixel));                  value = MAKECOLOUR(pc);
   
713                  if (g_xserver_be)                  if (g_xserver_be)
714                  {                  {
715                          *(out++) = value >> 8;                          BOUT16(out, value);
                         *(out++) = value;  
716                  }                  }
717                  else                  else
718                  {                  {
719                          *(out++) = value;                          LOUT16(out, value);
                         *(out++) = value >> 8;  
720                  }                  }
721          }          }
722  }  }
723    
724  static void  static void
725  translate24to24(uint8 * data, uint8 * out, uint8 * end)  translate24to24(const uint8 * data, uint8 * out, uint8 * end)
726  {  {
727          uint32 pixel;          uint32 pixel;
728          uint32 value;          uint32 value;
729            PixelColour pc;
730    
731          while (out < end)          if (g_xserver_be)
732          {          {
733                  pixel = *(data++) << 16;                  while (out < end)
                 pixel |= *(data++) << 8;  
                 pixel |= *(data++);  
   
                 value = make_colour(split_colour24(pixel));  
   
                 if (g_xserver_be)  
734                  {                  {
735                          *(out++) = value >> 16;                          pixel = *(data++) << 16;
736                          *(out++) = value >> 8;                          pixel |= *(data++) << 8;
737                          *(out++) = value;                          pixel |= *(data++);
738                            SPLITCOLOUR24(pixel, pc);
739                            value = MAKECOLOUR(pc);
740                            BOUT24(out, value);
741                  }                  }
742                  else          }
743            else
744            {
745                    while (out < end)
746                  {                  {
747                          *(out++) = value;                          pixel = *(data++) << 16;
748                          *(out++) = value >> 8;                          pixel |= *(data++) << 8;
749                          *(out++) = value >> 16;                          pixel |= *(data++);
750                            SPLITCOLOUR24(pixel, pc);
751                            value = MAKECOLOUR(pc);
752                            LOUT24(out, value);
753                  }                  }
754          }          }
755  }  }
756    
757  static void  static void
758  translate24to32(uint8 * data, uint8 * out, uint8 * end)  translate24to32(const uint8 * data, uint8 * out, uint8 * end)
759  {  {
760          uint32 pixel;          uint32 pixel;
761          uint32 value;          uint32 value;
762            PixelColour pc;
763    
764          while (out < end)          if (g_arch_match)
765          {          {
766                  pixel = *(data++) << 16;                  /* *INDENT-OFF* */
767                  pixel |= *(data++) << 8;                  REPEAT4
768                  pixel |= *(data++);                  (
769    #ifdef NEED_ALIGN
770                  value = make_colour(split_colour24(pixel));                          *(out++) = *(data++);
771                            *(out++) = *(data++);
772                  if (g_xserver_be)                          *(out++) = *(data++);
773                            *(out++) = 0;
774    #else
775                            *((uint32 *) out) = *((uint32 *) data);
776                            out += 4;
777                            data += 3;
778    #endif
779                    )
780                    /* *INDENT-ON* */
781            }
782            else if (g_xserver_be)
783            {
784                    while (out < end)
785                  {                  {
786                          *(out++) = value >> 24;                          pixel = *(data++) << 16;
787                          *(out++) = value >> 16;                          pixel |= *(data++) << 8;
788                          *(out++) = value >> 8;                          pixel |= *(data++);
789                          *(out++) = value;                          SPLITCOLOUR24(pixel, pc);
790                            value = MAKECOLOUR(pc);
791                            BOUT32(out, value);
792                  }                  }
793                  else          }
794            else
795            {
796                    while (out < end)
797                  {                  {
798                          *(out++) = value;                          pixel = *(data++) << 16;
799                          *(out++) = value >> 8;                          pixel |= *(data++) << 8;
800                          *(out++) = value >> 16;                          pixel |= *(data++);
801                          *(out++) = value >> 24;                          SPLITCOLOUR24(pixel, pc);
802                            value = MAKECOLOUR(pc);
803                            LOUT32(out, value);
804                  }                  }
805          }          }
806  }  }
# Line 587  translate24to32(uint8 * data, uint8 * ou Line 808  translate24to32(uint8 * data, uint8 * ou
808  static uint8 *  static uint8 *
809  translate_image(int width, int height, uint8 * data)  translate_image(int width, int height, uint8 * data)
810  {  {
811          int size = width * height * g_bpp / 8;          int size;
812          uint8 *out = (uint8 *) xmalloc(size);          uint8 *out;
813          uint8 *end = out + size;          uint8 *end;
814    
815            /* if server and xserver bpp match, */
816            /* and arch(endian) matches, no need to translate */
817            /* just return data */
818            if (g_arch_match)
819            {
820                    if (g_depth == 15 && g_server_bpp == 15)
821                            return data;
822                    if (g_depth == 16 && g_server_bpp == 16)
823                            return data;
824                    if (g_depth == 24 && g_bpp == 24 && g_server_bpp == 24)
825                            return data;
826            }
827    
828            size = width * height * (g_bpp / 8);
829            out = (uint8 *) xmalloc(size);
830            end = out + size;
831    
832          switch (g_server_bpp)          switch (g_server_bpp)
833          {          {
# Line 727  ui_init(void) Line 965  ui_init(void)
965                  TrueColorVisual = True;                  TrueColorVisual = True;
966          }          }
967    
968            test = 1;
969            g_host_be = !(BOOL) (*(uint8 *) (&test));
970            g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
971    
972          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))          if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
973          {          {
974                  /* we use a colourmap, so the default visual should do */                  /* we use a colourmap, so the default visual should do */
# Line 753  ui_init(void) Line 995  ui_init(void)
995                  calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);                  calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
996                  calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);                  calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
997                  calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);                  calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
998    
999                    /* if RGB video and everything is little endian */
1000                    if ((vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) &&
1001                        !g_xserver_be && !g_host_be)
1002                    {
1003                            if (g_depth <= 16 || (g_red_shift_l == 16 && g_green_shift_l == 8 &&
1004                                                  g_blue_shift_l == 0))
1005                            {
1006                                    g_arch_match = True;
1007                            }
1008                    }
1009    
1010                    if (g_arch_match)
1011                    {
1012                            DEBUG(("Architectures match, enabling little endian optimisations.\n"));
1013                    }
1014          }          }
1015    
1016          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
# Line 792  ui_init(void) Line 1050  ui_init(void)
1050                  g_ownbackstore = True;                  g_ownbackstore = True;
1051          }          }
1052    
         test = 1;  
         g_host_be = !(BOOL) (*(uint8 *) (&test));  
         g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);  
   
1053          /*          /*
1054           * Determine desktop size           * Determine desktop size
1055           */           */
# Line 868  BOOL Line 1122  BOOL
1122  ui_create_window(void)  ui_create_window(void)
1123  {  {
1124          uint8 null_pointer_mask[1] = { 0x80 };          uint8 null_pointer_mask[1] = { 0x80 };
1125          uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 };          uint8 null_pointer_data[24] = { 0x00 };
1126    
1127          XSetWindowAttributes attribs;          XSetWindowAttributes attribs;
1128          XClassHint *classhints;          XClassHint *classhints;
1129          XSizeHints *sizehints;          XSizeHints *sizehints;
# Line 885  ui_create_window(void) Line 1140  ui_create_window(void)
1140          attribs.override_redirect = g_fullscreen;          attribs.override_redirect = g_fullscreen;
1141          attribs.colormap = g_xcolmap;          attribs.colormap = g_xcolmap;
1142    
1143          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight,          g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), g_xpos, g_ypos, wndwidth,
1144                                0, g_depth, InputOutput, g_visual,                                wndheight, 0, g_depth, InputOutput, g_visual,
1145                                CWBackPixel | CWBackingStore | CWOverrideRedirect |                                CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
1146                                CWColormap | CWBorderPixel, &attribs);                                CWBorderPixel, &attribs);
1147    
1148          if (g_gc == NULL)          if (g_gc == NULL)
1149                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);                  g_gc = XCreateGC(g_display, g_wnd, 0, NULL);
1150    
1151            if (g_create_bitmap_gc == NULL)
1152                    g_create_bitmap_gc = XCreateGC(g_display, g_wnd, 0, NULL);
1153    
1154          if ((g_ownbackstore) && (g_backstore == 0))          if ((g_ownbackstore) && (g_backstore == 0))
1155          {          {
1156                  g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);                  g_backstore = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
# Line 925  ui_create_window(void) Line 1183  ui_create_window(void)
1183                  XFree(sizehints);                  XFree(sizehints);
1184          }          }
1185    
1186            if (g_embed_wnd)
1187            {
1188                    XReparentWindow(g_display, g_wnd, (Window) g_embed_wnd, 0, 0);
1189            }
1190    
1191          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |          input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
1192                  VisibilityChangeMask | FocusChangeMask;                  VisibilityChangeMask | FocusChangeMask;
1193    
# Line 956  ui_create_window(void) Line 1219  ui_create_window(void)
1219                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);                  XMaskEvent(g_display, VisibilityChangeMask, &xevent);
1220          }          }
1221          while (xevent.type != VisibilityNotify);          while (xevent.type != VisibilityNotify);
1222            g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1223    
1224          g_focused = False;          g_focused = False;
1225          g_mouse_in_wnd = False;          g_mouse_in_wnd = False;
# Line 973  ui_create_window(void) Line 1237  ui_create_window(void)
1237  }  }
1238    
1239  void  void
1240    ui_resize_window()
1241    {
1242            XSizeHints *sizehints;
1243            Pixmap bs;
1244    
1245            sizehints = XAllocSizeHints();
1246            if (sizehints)
1247            {
1248                    sizehints->flags = PMinSize | PMaxSize;
1249                    sizehints->min_width = sizehints->max_width = g_width;
1250                    sizehints->min_height = sizehints->max_height = g_height;
1251                    XSetWMNormalHints(g_display, g_wnd, sizehints);
1252                    XFree(sizehints);
1253            }
1254    
1255            if (!(g_fullscreen || g_embed_wnd))
1256            {
1257                    XResizeWindow(g_display, g_wnd, g_width, g_height);
1258            }
1259    
1260            /* create new backstore pixmap */
1261            if (g_backstore != 0)
1262            {
1263                    bs = XCreatePixmap(g_display, g_wnd, g_width, g_height, g_depth);
1264                    XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen));
1265                    XFillRectangle(g_display, bs, g_gc, 0, 0, g_width, g_height);
1266                    XCopyArea(g_display, g_backstore, bs, g_gc, 0, 0, g_width, g_height, 0, 0);
1267                    XFreePixmap(g_display, g_backstore);
1268                    g_backstore = bs;
1269            }
1270    }
1271    
1272    void
1273  ui_destroy_window(void)  ui_destroy_window(void)
1274  {  {
1275          if (g_IC != NULL)          if (g_IC != NULL)
# Line 1033  xwin_process_events(void) Line 1330  xwin_process_events(void)
1330    
1331                  switch (xevent.type)                  switch (xevent.type)
1332                  {                  {
1333                            case VisibilityNotify:
1334                                    g_Unobscured = xevent.xvisibility.state == VisibilityUnobscured;
1335                                    break;
1336                          case ClientMessage:                          case ClientMessage:
1337                                  /* the window manager told us to quit */                                  /* the window manager told us to quit */
1338                                  if ((xevent.xclient.message_type == g_protocol_atom)                                  if ((xevent.xclient.message_type == g_protocol_atom)
# Line 1311  ui_select(int rdp_socket) Line 1611  ui_select(int rdp_socket)
1611                                  error("select: %s\n", strerror(errno));                                  error("select: %s\n", strerror(errno));
1612    
1613                          case 0:                          case 0:
1614                                  /* TODO: if tv.tv_sec just times out                                  /* Abort serial read calls */
1615                                   * we will segfault.                                  if (s_timeout)
1616                                   * FIXME:                                          rdpdr_check_fds(&rfds, &wfds, (BOOL) True);
                                  */  
                                 //s_timeout = True;  
                                 //rdpdr_check_fds(&rfds, &wfds, (BOOL) True);  
1617                                  continue;                                  continue;
1618                  }                  }
1619    
# Line 1363  ui_create_bitmap(int width, int height, Line 1660  ui_create_bitmap(int width, int height,
1660          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1661                               (char *) tdata, width, height, bitmap_pad, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1662    
1663          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);
1664    
1665          XFree(image);          XFree(image);
1666          if (!g_owncolmap)          if (tdata != data)
1667                  xfree(tdata);                  xfree(tdata);
1668          return (HBITMAP) bitmap;          return (HBITMAP) bitmap;
1669  }  }
# Line 1405  ui_paint_bitmap(int x, int y, int cx, in Line 1702  ui_paint_bitmap(int x, int y, int cx, in
1702          }          }
1703    
1704          XFree(image);          XFree(image);
1705          if (!g_owncolmap)          if (tdata != data)
1706                  xfree(tdata);                  xfree(tdata);
1707  }  }
1708    
# Line 1421  ui_create_glyph(int width, int height, u Line 1718  ui_create_glyph(int width, int height, u
1718          XImage *image;          XImage *image;
1719          Pixmap bitmap;          Pixmap bitmap;
1720          int scanline;          int scanline;
         GC gc;  
1721    
1722          scanline = (width + 7) / 8;          scanline = (width + 7) / 8;
1723    
1724          bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, 1);
1725          gc = XCreateGC(g_display, bitmap, 0, NULL);          if (g_create_glyph_gc == 0)
1726                    g_create_glyph_gc = XCreateGC(g_display, bitmap, 0, NULL);
1727    
1728          image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data,          image = XCreateImage(g_display, g_visual, 1, ZPixmap, 0, (char *) data,
1729                               width, height, 8, scanline);                               width, height, 8, scanline);
# Line 1434  ui_create_glyph(int width, int height, u Line 1731  ui_create_glyph(int width, int height, u
1731          image->bitmap_bit_order = MSBFirst;          image->bitmap_bit_order = MSBFirst;
1732          XInitImage(image);          XInitImage(image);
1733    
1734          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);
1735    
1736          XFree(image);          XFree(image);
         XFreeGC(g_display, gc);  
1737          return (HGLYPH) bitmap;          return (HGLYPH) bitmap;
1738  }  }
1739    
# Line 1729  ui_patblt(uint8 opcode, Line 2025  ui_patblt(uint8 opcode,
2025          {          {
2026                  case 0: /* Solid */                  case 0: /* Solid */
2027                          SET_FOREGROUND(fgcolour);                          SET_FOREGROUND(fgcolour);
2028                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
2029                          break;                          break;
2030    
2031                  case 2: /* Hatch */                  case 2: /* Hatch */
# Line 1740  ui_patblt(uint8 opcode, Line 2036  ui_patblt(uint8 opcode,
2036                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
2037                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
2038                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
2039                          FILL_RECTANGLE(x, y, cx, cy);                          FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
2040                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
2041                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
2042                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1750  ui_patblt(uint8 opcode, Line 2046  ui_patblt(uint8 opcode,
2046                          for (i = 0; i != 8; i++)                          for (i = 0; i != 8; i++)
2047                                  ipattern[7 - i] = brush->pattern[i];                                  ipattern[7 - i] = brush->pattern[i];
2048                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);                          fill = (Pixmap) ui_create_glyph(8, 8, ipattern);
   
2049                          SET_FOREGROUND(bgcolour);                          SET_FOREGROUND(bgcolour);
2050                          SET_BACKGROUND(fgcolour);                          SET_BACKGROUND(fgcolour);
2051                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);                          XSetFillStyle(g_display, g_gc, FillOpaqueStippled);
2052                          XSetStipple(g_display, g_gc, fill);                          XSetStipple(g_display, g_gc, fill);
2053                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);                          XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);
2054                            FILL_RECTANGLE_BACKSTORE(x, y, cx, cy);
                         FILL_RECTANGLE(x, y, cx, cy);  
   
2055                          XSetFillStyle(g_display, g_gc, FillSolid);                          XSetFillStyle(g_display, g_gc, FillSolid);
2056                          XSetTSOrigin(g_display, g_gc, 0, 0);                          XSetTSOrigin(g_display, g_gc, 0, 0);
2057                          ui_destroy_glyph((HGLYPH) fill);                          ui_destroy_glyph((HGLYPH) fill);
# Line 1769  ui_patblt(uint8 opcode, Line 2062  ui_patblt(uint8 opcode,
2062          }          }
2063    
2064          RESET_FUNCTION(opcode);          RESET_FUNCTION(opcode);
2065    
2066            if (g_ownbackstore)
2067                    XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y);
2068  }  }
2069    
2070  void  void
# Line 1779  ui_screenblt(uint8 opcode, Line 2075  ui_screenblt(uint8 opcode,
2075          SET_FUNCTION(opcode);          SET_FUNCTION(opcode);
2076          if (g_ownbackstore)          if (g_ownbackstore)
2077          {          {
2078                  XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);                  if (g_Unobscured)
2079                  XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y);                  {
2080                            XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
2081                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
2082                                      y);
2083                    }
2084                    else
2085                    {
2086                            XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y);
2087                            XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x,
2088                                      y);
2089                    }
2090          }          }
2091          else          else
2092          {          {
# Line 1922  ui_draw_text(uint8 font, uint8 flags, in Line 2228  ui_draw_text(uint8 font, uint8 flags, in
2228    
2229          SET_FOREGROUND(bgcolour);          SET_FOREGROUND(bgcolour);
2230    
2231            /* Sometimes, the boxcx value is something really large, like
2232               32691. This makes XCopyArea fail with Xvnc. The code below
2233               is a quick fix. */
2234            if (boxx + boxcx > g_width)
2235                    boxcx = g_width - boxx;
2236    
2237          if (boxcx > 1)          if (boxcx > 1)
2238          {          {
2239                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);                  FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy);
# Line 2049  ui_desktop_restore(uint32 offset, int x, Line 2361  ui_desktop_restore(uint32 offset, int x,
2361    
2362          XFree(image);          XFree(image);
2363  }  }
2364    
2365    /* these do nothing here but are used in uiports */
2366    void
2367    ui_begin_update(void)
2368    {
2369    }
2370    
2371    void
2372    ui_end_update(void)
2373    {
2374    }

Legend:
Removed from v.619  
changed lines
  Added in v.821

  ViewVC Help
Powered by ViewVC 1.1.26