ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_x.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/video_x.cpp (file contents):
Revision 1.47 by cebix, 2001-07-01T00:46:37Z vs.
Revision 1.48 by cebix, 2001-07-01T14:38:03Z

# Line 124 | Line 124 | static XColor black, white;
124   static unsigned long black_pixel, white_pixel;
125   static int eventmask;
126  
127 < static XColor palette[256];                                                     // Color palette for indexed modes
127 > static int rshift, rloss, gshift, gloss, bshift, bloss; // Pixel format of DirectColor/TrueColor modes
128 >
129 > static XColor palette[256];                                                     // Color palette to be used as CLUT and gamma table
130   static bool palette_changed = false;                            // Flag: Palette changed, redraw thread must set new colors
131  
132   #ifdef ENABLE_FBDEV_DGA
# Line 203 | Line 205 | static void set_mac_frame_buffer(video_d
205          if (depth == VDEPTH_16BIT)
206                  layout = (xdepth == 15) ? FLAYOUT_HOST_555 : FLAYOUT_HOST_565;
207          else if (depth == VDEPTH_32BIT)
208 <                layour = (xdepth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT;
208 >                layout = (xdepth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT;
209          if (native_byte_order)
210                  MacFrameLayout = layout;
211          else
# Line 414 | Line 416 | driver_window::driver_window(const video
416          XSetWindowAttributes wattr;
417          wattr.event_mask = eventmask = win_eventmask;
418          wattr.background_pixel = black_pixel;
419 <        wattr.colormap = cmap[0];
419 >        wattr.colormap = (mode.depth == VDEPTH_1BIT && vis->c_class == PseudoColor ? DefaultColormap(x_display, screen) : cmap[0]);
420          w = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
421 <                InputOutput, vis, CWEventMask | CWBackPixel | ((mode.depth == VDEPTH_1BIT || cmap[0] == 0) ? 0 : CWColormap), &wattr);
421 >                InputOutput, vis, CWEventMask | CWBackPixel | (vis->c_class == PseudoColor || vis->c_class == DirectColor ? CWColormap : 0), &wattr);
422  
423          // Set window name/class
424          set_window_name(w, STR_WINDOW_TITLE);
# Line 445 | Line 447 | driver_window::driver_window(const video
447          XMapWindow(x_display, w);
448          wait_mapped(w);
449  
450 +        // 1-bit mode is big-endian; if the X server is little-endian, we can't
451 +        // use SHM because that doesn't allow changing the image byte order
452 +        bool need_msb_image = (mode.depth == VDEPTH_1BIT && XImageByteOrder(x_display) == LSBFirst);
453 +
454          // Try to create and attach SHM image
455 <        if (local_X11 && XShmQueryExtension(x_display)) {
455 >        if (local_X11 && !need_msb_image && XShmQueryExtension(x_display)) {
456  
457                  // Create SHM image ("height + 2" for safety)
458                  img = XShmCreateImage(x_display, vis, mode.depth == VDEPTH_1BIT ? 1 : xdepth, mode.depth == VDEPTH_1BIT ? XYBitmap : ZPixmap, 0, &shminfo, width, height);
# Line 478 | Line 484 | driver_window::driver_window(const video
484                  img = XCreateImage(x_display, vis, mode.depth == VDEPTH_1BIT ? 1 : xdepth, mode.depth == VDEPTH_1BIT ? XYBitmap : ZPixmap, 0, (char *)the_buffer_copy, aligned_width, aligned_height, 32, bytes_per_row);
485          }
486  
487 <        // 1-Bit mode is big-endian
482 <        if (mode.depth == VDEPTH_1BIT) {
487 >        if (need_msb_image) {
488                  img->byte_order = MSBFirst;
489                  img->bitmap_bit_order = MSBFirst;
490          }
# Line 514 | Line 519 | driver_window::driver_window(const video
519          native_byte_order = (XImageByteOrder(x_display) == LSBFirst);
520   #endif
521   #ifdef ENABLE_VOSF
522 <        Screen_blitter_init(&visualInfo, native_byte_order);
522 >        Screen_blitter_init(&visualInfo, native_byte_order, mode.depth);
523   #endif
524  
525          // Set VideoMonitor
# Line 782 | Line 787 | driver_fbdev::driver_fbdev(const video_m
787   #if REAL_ADDRESSING || DIRECT_ADDRESSING
788          // Screen_blitter_init() returns TRUE if VOSF is mandatory
789          // i.e. the framebuffer update function is not Blit_Copy_Raw
790 <        use_vosf = Screen_blitter_init(&visualInfo, true);
790 >        use_vosf = Screen_blitter_init(&visualInfo, true, mode.depth);
791          
792          if (use_vosf) {
793            // Allocate memory for frame buffer (SIZE is extended to page-boundary)
# Line 898 | Line 903 | driver_xf86dga::driver_xf86dga(const vid
903   #if REAL_ADDRESSING || DIRECT_ADDRESSING
904          // Screen_blitter_init() returns TRUE if VOSF is mandatory
905          // i.e. the framebuffer update function is not Blit_Copy_Raw
906 <        use_vosf = Screen_blitter_init(&visualInfo, true);
906 >        use_vosf = Screen_blitter_init(&visualInfo, true, mode.depth);
907          
908          if (use_vosf) {
909            // Allocate memory for frame buffer (SIZE is extended to page-boundary)
# Line 1022 | Line 1027 | static void keycode_init(void)
1027   // Open display for specified mode
1028   static bool video_open(const video_mode &mode)
1029   {
1030 +        // Load gray ramp to color map
1031 +        int num = (vis->c_class == DirectColor ? vis->map_entries : 256);
1032 +        for (int i=0; i<num; i++) {
1033 +                int c = (i * 256) / num;
1034 +                palette[i].red = c * 0x0101;
1035 +                palette[i].green = c * 0x0101;
1036 +                palette[i].blue = c * 0x0101;
1037 +                if (vis->c_class == PseudoColor)
1038 +                        palette[i].pixel = i;
1039 +                palette[i].flags = DoRed | DoGreen | DoBlue;
1040 +        }
1041 +        if (cmap[0] && cmap[1]) {
1042 +                XStoreColors(x_display, cmap[0], palette, num);
1043 +                XStoreColors(x_display, cmap[1], palette, num);
1044 +        }
1045 +
1046          // Create display driver object of requested type
1047          switch (display_type) {
1048                  case DISPLAY_WINDOW:
# Line 1186 | Line 1207 | bool VideoInit(bool classic)
1207          if (color_class == PseudoColor || color_class == DirectColor) {
1208                  cmap[0] = XCreateColormap(x_display, rootwin, vis, AllocAll);
1209                  cmap[1] = XCreateColormap(x_display, rootwin, vis, AllocAll);
1210 +        }
1211  
1212 <                int num = 256;
1213 <                if (color_class == DirectColor) {
1214 <                        num = vis->map_entries;
1215 <
1216 <                        // Preset pixel values for gamma table
1217 <                        uint32 rmask = vis->red_mask, gmask = vis->green_mask, bmask = vis->blue_mask;
1218 <                        uint32 mask;
1219 <                        int rloss = 8, rshift = 0;
1220 <                        for (mask=rmask; !(mask&1); mask>>=1)
1221 <                                ++rshift;
1222 <                        for (; mask&1; mask>>=1)
1223 <                                --rloss;
1224 <                        int gloss = 8, gshift = 0;
1225 <                        for (mask=gmask; !(mask&1); mask>>=1)
1226 <                                ++gshift;
1227 <                        for (; mask&1; mask>>=1)
1228 <                                --gloss;
1229 <                        int bloss = 8, bshift = 0;
1230 <                        for (mask=bmask; !(mask&1); mask>>=1)
1231 <                                ++bshift;
1232 <                        for (; mask&1; mask>>=1)
1233 <                                --bloss;
1212 <                        for (int i=0; i<num; i++) {
1213 <                                int c = (i * 256) / num;
1214 <                                palette[i].pixel = ((c >> rloss) << rshift) | ((c >> gloss) << gshift) | ((c >> bloss) << bshift);
1215 <                        }
1216 <                }
1217 <
1218 <                // Load gray ramp
1212 >        // Find pixel format of direct modes
1213 >        if (color_class == DirectColor || color_class == TrueColor) {
1214 >                rshift = gshift = bshift = 0;
1215 >                rloss = gloss = bloss = 8;
1216 >                uint32 mask;
1217 >                for (mask=vis->red_mask; !(mask&1); mask>>=1)
1218 >                        ++rshift;
1219 >                for (; mask&1; mask>>=1)
1220 >                        --rloss;
1221 >                for (mask=vis->green_mask; !(mask&1); mask>>=1)
1222 >                        ++gshift;
1223 >                for (; mask&1; mask>>=1)
1224 >                        --gloss;
1225 >                for (mask=vis->blue_mask; !(mask&1); mask>>=1)
1226 >                        ++bshift;
1227 >                for (; mask&1; mask>>=1)
1228 >                        --bloss;
1229 >        }
1230 >
1231 >        // Preset palette pixel values for gamma table
1232 >        if (color_class == DirectColor) {
1233 >                int num = vis->map_entries;
1234                  for (int i=0; i<num; i++) {
1235                          int c = (i * 256) / num;
1236 <                        palette[i].red = c * 0x0101;
1222 <                        palette[i].green = c * 0x0101;
1223 <                        palette[i].blue = c * 0x0101;
1224 <                        if (color_class == PseudoColor)
1225 <                                palette[i].pixel = i;
1226 <                        palette[i].flags = DoRed | DoGreen | DoBlue;
1236 >                        palette[i].pixel = ((c >> rloss) << rshift) | ((c >> gloss) << gshift) | ((c >> bloss) << bshift);
1237                  }
1228                XStoreColors(x_display, cmap[0], palette, num);
1238          }
1239  
1240          // Get screen mode from preferences
# Line 1261 | Line 1270 | bool VideoInit(bool classic)
1270          else if (default_height > DisplayHeight(x_display, screen))
1271                  default_height = DisplayHeight(x_display, screen);
1272  
1273 <        // Mac screen depth is always 1 bit in Classic mode, but follows X depth otherwise
1274 <        int depth = (classic_mode ? 1 : xdepth);
1266 <        video_depth depth_mode = DepthModeForPixelDepth(depth);
1273 >        // Mac screen depth follows X depth
1274 >        video_depth default_depth = DepthModeForPixelDepth(xdepth);
1275  
1276          // Construct list of supported modes
1277          if (display_type == DISPLAY_WINDOW) {
1278                  if (classic)
1279 <                        add_mode(512, 342, 0x80, 64, depth_mode);
1279 >                        add_mode(512, 342, 0x80, 64, VDEPTH_1BIT);
1280                  else {
1281 <                        add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth_mode), depth_mode);
1282 <                        add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth_mode), depth_mode);
1283 <                        add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth_mode), depth_mode);
1284 <                        add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth_mode), depth_mode);
1285 <                        add_mode(1280, 1024, 0x84, TrivialBytesPerRow(1280, depth_mode), depth_mode);
1281 >                        if (default_depth != VDEPTH_1BIT) { // 1-bit modes are always available
1282 >                                add_mode(512, 384, 0x80, TrivialBytesPerRow(512, VDEPTH_1BIT), VDEPTH_1BIT);
1283 >                                add_mode(640, 480, 0x81, TrivialBytesPerRow(640, VDEPTH_1BIT), VDEPTH_1BIT);
1284 >                                add_mode(800, 600, 0x82, TrivialBytesPerRow(800, VDEPTH_1BIT), VDEPTH_1BIT);
1285 >                                add_mode(832, 624, 0x83, TrivialBytesPerRow(832, VDEPTH_1BIT), VDEPTH_1BIT);
1286 >                                add_mode(1024, 768, 0x84, TrivialBytesPerRow(1024, VDEPTH_1BIT), VDEPTH_1BIT);
1287 >                                add_mode(1152, 870, 0x85, TrivialBytesPerRow(1152, VDEPTH_1BIT), VDEPTH_1BIT);
1288 >                                add_mode(1280, 1024, 0x86, TrivialBytesPerRow(1280, VDEPTH_1BIT), VDEPTH_1BIT);
1289 >                                add_mode(1600, 1200, 0x87, TrivialBytesPerRow(1600, VDEPTH_1BIT), VDEPTH_1BIT);
1290 >                        }
1291 >                        add_mode(512, 384, 0x80, TrivialBytesPerRow(512, default_depth), default_depth);
1292 >                        add_mode(640, 480, 0x81, TrivialBytesPerRow(640, default_depth), default_depth);
1293 >                        add_mode(800, 600, 0x82, TrivialBytesPerRow(800, default_depth), default_depth);
1294 >                        add_mode(832, 624, 0x83, TrivialBytesPerRow(832, default_depth), default_depth);
1295 >                        add_mode(1024, 768, 0x84, TrivialBytesPerRow(1024, default_depth), default_depth);
1296 >                        add_mode(1152, 870, 0x85, TrivialBytesPerRow(1152, default_depth), default_depth);
1297 >                        add_mode(1280, 1024, 0x86, TrivialBytesPerRow(1280, default_depth), default_depth);
1298 >                        add_mode(1600, 1200, 0x87, TrivialBytesPerRow(1600, default_depth), default_depth);
1299                  }
1300          } else
1301 <                add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, depth_mode), depth_mode);
1301 >                add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, default_depth), default_depth);
1302  
1303          // Find requested default mode and open display
1304          if (VideoModes.size() == 1)
1305                  return video_open(VideoModes[0]);
1306          else {
1307                  // Find mode with specified dimensions
1308 <                std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
1309 <                while (i != end) {
1310 <                        if (i->x == default_width && i->y == default_height)
1308 >                std::vector<video_mode>::const_iterator i, end = VideoModes.end();
1309 >                for (i = VideoModes.begin(); i != end; ++i) {
1310 >                        if (i->x == default_width && i->y == default_height && i->depth == default_depth)
1311                                  return video_open(*i);
1291                        ++i;
1312                  }
1313                  return video_open(VideoModes[0]);
1314          }
# Line 1420 | Line 1440 | void video_set_palette(uint8 *pal)
1440                  p->red = pal[c*3 + 0] * 0x0101;
1441                  p->green = pal[c*3 + 1] * 0x0101;
1442                  p->blue = pal[c*3 + 2] * 0x0101;
1443 <                if (!IsDirectMode(VideoMonitor.mode))
1443 >                if (vis->c_class == PseudoColor)
1444                          p->pixel = i;
1445                  p->flags = DoRed | DoGreen | DoBlue;
1446                  p++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines