/[rdesktop]/sourceforge.net/trunk/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/trunk/rdesktop/xwin.c

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

revision 517 by matthewc, Tue Oct 28 03:30:51 2003 UTC revision 527 by matthewc, Wed Oct 29 08:15:02 2003 UTC
# Line 57  static BOOL g_mouse_in_wnd; Line 57  static BOOL g_mouse_in_wnd;
57  /* endianness */  /* endianness */
58  static BOOL g_host_be;  static BOOL g_host_be;
59  static BOOL g_xserver_be;  static BOOL g_xserver_be;
60    static int g_red_shift_r, g_blue_shift_r, g_green_shift_r;
61    static int g_red_shift_l, g_blue_shift_l, g_green_shift_l;
62    
63  /* software backing store */  /* software backing store */
64  static BOOL g_ownbackstore;  static BOOL g_ownbackstore;
# Line 112  BOOL g_owncolmap = False; Line 114  BOOL g_owncolmap = False;
114  static Colormap g_xcolmap;  static Colormap g_xcolmap;
115  static uint32 *g_colmap = NULL;  static uint32 *g_colmap = NULL;
116    
117  #define TRANSLATE(col)          ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : translate_colour(g_colmap[col]) )  #define TRANSLATE(col)          ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] )
118  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));  #define SET_FOREGROUND(col)     XSetForeground(g_display, g_gc, TRANSLATE(col));
119  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));  #define SET_BACKGROUND(col)     XSetBackground(g_display, g_gc, TRANSLATE(col));
120    
# Line 197  split_colour24(uint32 colour) Line 199  split_colour24(uint32 colour)
199  }  }
200    
201  static uint32  static uint32
202  make_colour16(PixelColour pc)  make_colour(PixelColour pc)
203  {  {
204          pc.red = (pc.red * 0x1f) / 0xff;          return (((pc.red >> g_red_shift_r) << g_red_shift_l)
205          pc.green = (pc.green * 0x3f) / 0xff;                  | ((pc.green >> g_green_shift_r) << g_green_shift_l)
206          pc.blue = (pc.blue * 0x1f) / 0xff;                  | ((pc.blue >> g_blue_shift_r) << g_blue_shift_l));
         return (pc.red << 11) | (pc.green << 5) | pc.blue;  
 }  
   
 static uint32  
 make_colour24(PixelColour pc)  
 {  
         if (g_xserver_be)  
         {  
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
         else  
         {  
                 return (pc.red << 16) | (pc.green << 8) | pc.blue;  
         }  
 }  
   
 static uint32  
 make_colour32(PixelColour pc)  
 {  
         if (g_xserver_be)  
         {  
                 return pc.red | (pc.green << 8) | (pc.blue << 16);  
         }  
         else  
         {  
                 return (pc.red << 16) | (pc.green << 8) | pc.blue;  
         }  
207  }  }
208    
209  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }  #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); }
# Line 239  make_colour32(PixelColour pc) Line 214  make_colour32(PixelColour pc)
214  static uint32  static uint32
215  translate_colour(uint32 colour)  translate_colour(uint32 colour)
216  {  {
217            PixelColour pc;
218          switch (g_server_bpp)          switch (g_server_bpp)
219          {          {
220                  case 15:                  case 15:
221                          switch (g_bpp)                          pc = split_colour15(colour);
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour15(colour));  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour15(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour15(colour));  
                                         break;  
                         }  
222                          break;                          break;
223                  case 16:                  case 16:
224                          switch (g_bpp)                          pc = split_colour16(colour);
                         {  
                                 case 16:  
                                         break;  
                                 case 24:  
                                         colour = make_colour24(split_colour16(colour));  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour16(colour));  
                                         break;  
                         }  
225                          break;                          break;
226                  case 24:                  case 24:
227                          switch (g_bpp)                          pc = split_colour24(colour);
                         {  
                                 case 16:  
                                         colour = make_colour16(split_colour24(colour));  
                                         break;  
                                 case 24:  
                                         break;  
                                 case 32:  
                                         colour = make_colour32(split_colour24(colour));  
                                         break;  
                         }  
228                          break;                          break;
229          }          }
230          return colour;          return make_colour(pc);
231  }  }
232    
233  static void  static void
# Line 293  translate8to8(uint8 * data, uint8 * out, Line 238  translate8to8(uint8 * data, uint8 * out,
238  }  }
239    
240  static void  static void
241  translate8to16(uint8 * data, uint16 * out, uint16 * end)  translate8to16(uint8 * data, uint8 * out, uint8 * end)
242  {  {
243            uint16 value;
244    
245          while (out < end)          while (out < end)
246                  *(out++) = (uint16) g_colmap[*(data++)];          {
247                    value = (uint16) g_colmap[*(data++)];
248                    
249                    if (g_xserver_be)
250                    {
251                            *(out++) = value >> 8;
252                            *(out++) = value;
253                    }
254                    else
255                    {
256                            *(out++) = value;
257                            *(out++) = value >> 8;
258                    }
259            }
260  }  }
261    
262  /* little endian - conversion happens when colourmap is built */  /* little endian - conversion happens when colourmap is built */
# Line 308  translate8to24(uint8 * data, uint8 * out Line 268  translate8to24(uint8 * data, uint8 * out
268          while (out < end)          while (out < end)
269          {          {
270                  value = g_colmap[*(data++)];                  value = g_colmap[*(data++)];
271                  *(out++) = value;                  
272                  *(out++) = value >> 8;                  if (g_xserver_be)
273                  *(out++) = value >> 16;                  {
274                            *(out++) = value >> 16;
275                            *(out++) = value >> 8;
276                            *(out++) = value;
277                    }
278                    else
279                    {
280                            *(out++) = value;
281                            *(out++) = value >> 8;
282                            *(out++) = value >> 16;
283                    }
284          }          }
285  }  }
286    
287  static void  static void
288  translate8to32(uint8 * data, uint32 * out, uint32 * end)  translate8to32(uint8 * data, uint8 * out, uint8 * end)
289  {  {
290            uint32 value;
291    
292          while (out < end)          while (out < end)
293                  *(out++) = g_colmap[*(data++)];          {
294                    value = g_colmap[*(data++)];
295    
296                    if (g_xserver_be)
297                    {
298                            *(out++) = value >> 24;
299                            *(out++) = value >> 16;
300                            *(out++) = value >> 8;
301                            *(out++) = value;
302                    }
303                    else
304                    {
305                            *(out++) = value;
306                            *(out++) = value >> 8;
307                            *(out++) = value >> 16;
308                            *(out++) = value >> 24;
309                    }
310            }
311  }  }
312    
313  /* todo the remaining translate function might need some big endian check ?? */  /* todo the remaining translate function might need some big endian check ?? */
# Line 335  translate15to16(uint16 * data, uint8 * o Line 324  translate15to16(uint16 * data, uint8 * o
324    
325                  if (g_host_be)                  if (g_host_be)
326                  {                  {
327                  BSWAP16(pixel)}                          BSWAP16(pixel);
328                    }
329    
330                  value = make_colour16(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
331    
332                  if (g_xserver_be)                  if (g_xserver_be)
333                  {                  {
# Line 364  translate15to24(uint16 * data, uint8 * o Line 354  translate15to24(uint16 * data, uint8 * o
354    
355                  if (g_host_be)                  if (g_host_be)
356                  {                  {
357                  BSWAP16(pixel)}                          BSWAP16(pixel);
358                    }
359    
360                  value = make_colour24(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
361                  if (g_xserver_be)                  if (g_xserver_be)
362                  {                  {
363                          *(out++) = value >> 16;                          *(out++) = value >> 16;
# Line 397  translate15to32(uint16 * data, uint8 * o Line 388  translate15to32(uint16 * data, uint8 * o
388                          BSWAP16(pixel);                          BSWAP16(pixel);
389                  }                  }
390    
391                  value = make_colour32(split_colour15(pixel));                  value = make_colour(split_colour15(pixel));
392    
393                  if (g_xserver_be)                  if (g_xserver_be)
394                  {                  {
# Line 457  translate16to24(uint16 * data, uint8 * o Line 448  translate16to24(uint16 * data, uint8 * o
448    
449                  if (g_host_be)                  if (g_host_be)
450                  {                  {
451                  BSWAP16(pixel)}                          BSWAP16(pixel);
452                    }
453    
454                  value = make_colour24(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
455    
456                  if (g_xserver_be)                  if (g_xserver_be)
457                  {                  {
# Line 490  translate16to32(uint16 * data, uint8 * o Line 482  translate16to32(uint16 * data, uint8 * o
482                  {                  {
483                  BSWAP16(pixel)}                  BSWAP16(pixel)}
484    
485                  value = make_colour32(split_colour16(pixel));                  value = make_colour(split_colour16(pixel));
486    
487                  if (g_xserver_be)                  if (g_xserver_be)
488                  {                  {
# Line 520  translate24to16(uint8 * data, uint8 * ou Line 512  translate24to16(uint8 * data, uint8 * ou
512                  pixel |= *(data++) << 8;                  pixel |= *(data++) << 8;
513                  pixel |= *(data++);                  pixel |= *(data++);
514    
515                  value = (uint16) make_colour16(split_colour24(pixel));                  value = (uint16) make_colour(split_colour24(pixel));
516    
517                  if (g_xserver_be)                  if (g_xserver_be)
518                  {                  {
# Line 625  translate_image(int width, int height, u Line 617  translate_image(int width, int height, u
617                                          translate8to8(data, out, end);                                          translate8to8(data, out, end);
618                                          break;                                          break;
619                                  case 16:                                  case 16:
620                                          translate8to16(data, (uint16 *) out, (uint16 *) end);                                          translate8to16(data, out, end);
621                                          break;                                          break;
622                                  case 24:                                  case 24:
623                                          translate8to24(data, out, end);                                          translate8to24(data, out, end);
624                                          break;                                          break;
625                                  case 32:                                  case 32:
626                                          translate8to32(data, (uint32 *) out, (uint32 *) end);                                          translate8to32(data, out, end);
627                                          break;                                          break;
628                          }                          }
629                          break;                          break;
# Line 664  get_key_state(unsigned int state, uint32 Line 656  get_key_state(unsigned int state, uint32
656          return (state & keysymMask) ? True : False;          return (state & keysymMask) ? True : False;
657  }  }
658    
659    static void
660    calculate_shifts(uint32 mask, int *shift_r, int *shift_l)
661    {
662            *shift_l = ffs(mask) - 1;
663            mask >>= *shift_l;
664            *shift_r = 8 - ffs(mask & ~(mask >> 1));
665    }
666    
667  BOOL  BOOL
668  ui_init(void)  ui_init(void)
669  {  {
670            XVisualInfo vi;
671          XPixmapFormatValues *pfm;          XPixmapFormatValues *pfm;
672          uint16 test;          uint16 test;
673          int i;          int i, screen_num;
674    
675          g_display = XOpenDisplay(NULL);          g_display = XOpenDisplay(NULL);
676          if (g_display == NULL)          if (g_display == NULL)
# Line 678  ui_init(void) Line 679  ui_init(void)
679                  return False;                  return False;
680          }          }
681    
682            screen_num = DefaultScreen(g_display);
683          g_x_socket = ConnectionNumber(g_display);          g_x_socket = ConnectionNumber(g_display);
684          g_screen = DefaultScreenOfDisplay(g_display);          g_screen = ScreenOfDisplay(g_display, screen_num);
         g_visual = DefaultVisualOfScreen(g_screen);  
685          g_depth = DefaultDepthOfScreen(g_screen);          g_depth = DefaultDepthOfScreen(g_screen);
686    
687            if (g_server_bpp == 8)
688            {
689                    /* we use a colourmap, so any visual should do */
690                    g_visual = DefaultVisualOfScreen(g_screen);
691            }
692            else
693            {
694                    /* need a truecolour visual */
695                    if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
696                    {
697                            error("The display does not support true colour - high colour support unavailable.\n");
698                            return False;
699                    }
700    
701                    g_visual = vi.visual;
702                    g_owncolmap = False;
703                    calculate_shifts(vi.red_mask,   &g_red_shift_r,   &g_red_shift_l);
704                    calculate_shifts(vi.blue_mask,  &g_blue_shift_r,  &g_blue_shift_l);
705                    calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
706            }
707    
708          pfm = XListPixmapFormats(g_display, &i);          pfm = XListPixmapFormats(g_display, &i);
709          if (pfm != NULL)          if (pfm != NULL)
710          {          {
# Line 705  ui_init(void) Line 727  ui_init(void)
727                  return False;                  return False;
728          }          }
729    
         /* private colour map code only works for 8 bpp */  
         if (g_owncolmap && (g_bpp > 8))  
                 g_owncolmap = False;  
   
730          if (!g_owncolmap)          if (!g_owncolmap)
731          {          {
732                  g_xcolmap = DefaultColormapOfScreen(g_screen);                  g_xcolmap = DefaultColormapOfScreen(g_screen);
# Line 780  ui_init(void) Line 798  ui_init(void)
798    
799          xclip_init();          xclip_init();
800    
801          /* todo take this out when high colour is done */          DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth));
         printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth);  
802    
803          return True;          return True;
804  }  }
# Line 1255  ui_create_bitmap(int width, int height, Line 1272  ui_create_bitmap(int width, int height,
1272          XImage *image;          XImage *image;
1273          Pixmap bitmap;          Pixmap bitmap;
1274          uint8 *tdata;          uint8 *tdata;
1275            int bitmap_pad;
1276    
1277            if (g_server_bpp == 8)
1278            {
1279                    bitmap_pad = 8;
1280            }
1281            else
1282            {
1283                    bitmap_pad = g_bpp;
1284    
1285                    if (g_bpp == 24)
1286                            bitmap_pad = 32;
1287            }
1288    
1289          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1290          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);          bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth);
1291          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1292                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1293    
1294          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);          XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height);
1295    
# Line 1274  ui_paint_bitmap(int x, int y, int cx, in Line 1304  ui_paint_bitmap(int x, int y, int cx, in
1304  {  {
1305          XImage *image;          XImage *image;
1306          uint8 *tdata;          uint8 *tdata;
1307            int bitmap_pad;
1308    
1309            if (g_server_bpp == 8)
1310            {
1311                    bitmap_pad = 8;
1312            }
1313            else
1314            {
1315                    bitmap_pad = g_bpp;
1316    
1317                    if (g_bpp == 24)
1318                            bitmap_pad = 32;
1319            }
1320    
1321          tdata = (g_owncolmap ? data : translate_image(width, height, data));          tdata = (g_owncolmap ? data : translate_image(width, height, data));
1322          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,          image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0,
1323                               (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0);                               (char *) tdata, width, height, bitmap_pad, 0);
1324    
1325          if (g_ownbackstore)          if (g_ownbackstore)
1326          {          {
# Line 1502  ui_create_colourmap(COLOURMAP * colours) Line 1546  ui_create_colourmap(COLOURMAP * colours)
1546    
1547                          }                          }
1548    
1549                            map[i] = colour;
                         /* byte swap here to make translate_image faster */  
                         map[i] = translate_colour(colour);  
1550                  }                  }
1551                  return map;                  return map;
1552          }          }

Legend:
Removed from v.517  
changed lines
  Added in v.527

  ViewVC Help
Powered by ViewVC 1.1.26