~ubuntu-branches/ubuntu/vivid/basilisk2/vivid

« back to all changes in this revision

Viewing changes to src/SDL/video_sdl.cpp

  • Committer: Package Import Robot
  • Author(s): Jonas Smedegaard, Jonas Smedegaard, Jérémy Lal, Giulio Paci
  • Date: 2012-05-19 02:08:30 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120519020830-o59ui1wsfftg55m6
Tags: 0.9.20120331-1
* Upstream update

[ Jonas Smedegaard ]
* Drop local CDBS snippets: All included in main cdbs now.
* Use source format 3.0 (quilt), and stop including patchsys-quilt.mk.
  Stop build-depending on quilt, patchutils.
* Add full licensing header to debian/rules, and update copyright
  years.
* Add README.source (and drop outdated README.cdbs-tweaks).
* Refresh patches with shortening quilt options --no-index
  --no-timestamps -pab, and fix their path prefix.
* Rewrite copyright file using draft DEP-5 format.
* Update control file Vcs-* fields: Packaging moved to Git.
* Ease building with git-buildpackage:
  + Add gbp.conf, enabling pristine-tar and tag signing.
  + Git-ignore quilt .pc dir.
* Bump debhelper compat level to 7.
* Update Vcs-Browser field to use anonscm.debian.org.
* Add Giulio Paci and Jérémy Lal as uploaders, and permit Debian
  Maintainers to upload.

[ Jérémy Lal ]
* Drop patch 1002 to fix capitalized flag: corrected upstream.

[ Giulio Paci ]
* Restart package development.
  Closes: #662175.
* Add patches to fix compilation and documentation.
* Provide JIT flavor on supported architectures (i386 and amd64).
* Bump standards-version to 3.9.3.
* Update copyright file:
  + Adjust licenses now clarified/improved upstream.
* Update ChangeLog.cvs.
* Enable CDBS autogeneration of autotools files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  video_sdl.cpp - Video/graphics emulation, SDL specific stuff
3
3
 *
4
 
 *  Basilisk II (C) 1997-2005 Christian Bauer
 
4
 *  Basilisk II (C) 1997-2008 Christian Bauer
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
66
66
#define DEBUG 0
67
67
#include "debug.h"
68
68
 
69
 
 
70
69
// Supported video modes
71
70
using std::vector;
72
71
static vector<VIDEO_MODE> VideoModes;
136
135
static volatile bool cursor_changed = false;            // Flag: cursor changed, redraw_func must update the cursor
137
136
static SDL_Color sdl_palette[256];                                      // Color palette to be used as CLUT and gamma table
138
137
static bool sdl_palette_changed = false;                        // Flag: Palette changed, redraw thread must set new colors
139
 
static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK;
 
138
static const int sdl_eventmask = SDL_MOUSEEVENTMASK | SDL_KEYEVENTMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK | SDL_ACTIVEEVENTMASK;
140
139
 
141
140
// Mutex to protect SDL events
142
141
static SDL_mutex *sdl_events_lock = NULL;
197
196
 
198
197
static void *vm_acquire_framebuffer(uint32 size)
199
198
{
200
 
        return vm_acquire(size);
 
199
        // always try to reallocate framebuffer at the same address
 
200
        static void *fb = VM_MAP_FAILED;
 
201
        if (fb != VM_MAP_FAILED) {
 
202
                if (vm_acquire_fixed(fb, size) < 0) {
 
203
#ifndef SHEEPSHAVER
 
204
                        printf("FATAL: Could not reallocate framebuffer at previous address\n");
 
205
#endif
 
206
                        fb = VM_MAP_FAILED;
 
207
                }
 
208
        }
 
209
        if (fb == VM_MAP_FAILED)
 
210
                fb = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT);
 
211
        return fb;
201
212
}
202
213
 
203
214
static inline void vm_release_framebuffer(void *fb, uint32 size)
611
622
};
612
623
 
613
624
class driver_window;
 
625
#ifdef ENABLE_VOSF
614
626
static void update_display_window_vosf(driver_window *drv);
615
 
static void update_display_dynamic(int ticker, driver_window *drv);
616
 
static void update_display_static(driver_window *drv);
 
627
#endif
 
628
static void update_display_static(driver_base *drv);
617
629
 
618
630
class driver_window : public driver_base {
 
631
#ifdef ENABLE_VOSF
619
632
        friend void update_display_window_vosf(driver_window *drv);
620
 
        friend void update_display_dynamic(int ticker, driver_window *drv);
621
 
        friend void update_display_static(driver_window *drv);
 
633
#endif
 
634
        friend void update_display_static(driver_base *drv);
622
635
 
623
636
public:
624
637
        driver_window(SDL_monitor_desc &monitor);
719
732
 *  Windowed display driver
720
733
 */
721
734
 
722
 
static int SDL_display_opened = FALSE;
 
735
static bool SDL_display_opened = false;
723
736
 
724
737
// Open display
725
738
driver_window::driver_window(SDL_monitor_desc &m)
726
739
        : driver_base(m), mouse_grabbed(false)
727
740
{
728
741
        int width = VIDEO_MODE_X, height = VIDEO_MODE_Y;
729
 
        int aligned_width = (width + 15) & ~15;
730
742
        int aligned_height = (height + 15) & ~15;
731
743
 
732
744
        // Set absolute mouse mode
747
759
        if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
748
760
                return;
749
761
 
750
 
        SDL_display_opened = TRUE;
 
762
        SDL_display_opened = true;
751
763
 
752
764
#ifdef ENABLE_VOSF
753
765
        use_vosf = true;
880
892
        : driver_base(m)
881
893
{
882
894
        int width = VIDEO_MODE_X, height = VIDEO_MODE_Y;
883
 
        int aligned_width = (width + 15) & ~15;
884
895
        int aligned_height = (height + 15) & ~15;
885
896
 
886
897
        // Set absolute mouse mode
1050
1061
bool SDL_monitor_desc::video_open(void)
1051
1062
{
1052
1063
        D(bug("video_open()\n"));
 
1064
#if DEBUG
1053
1065
        const VIDEO_MODE &mode = get_current_mode();
1054
 
#if DEBUG
1055
1066
        D(bug("Current video mode:\n"));
1056
1067
        D(bug(" %dx%d (ID %02x), %d bpp\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << (VIDEO_MODE_DEPTH & 0x0f)));
1057
1068
#endif
1226
1237
                                continue;
1227
1238
                        if (w == 512 && h == 384)
1228
1239
                                continue;
1229
 
#ifdef ENABLE_VOSF
1230
1240
                        for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++)
1231
1241
                                add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)d), d);
1232
 
#else
1233
 
                        add_mode(display_type, w, h, video_modes[i].resolution_id, TrivialBytesPerRow(w, (video_depth)default_depth), default_depth);
1234
 
#endif
1235
1242
                }
1236
1243
        }
1237
1244
 
1531
1538
#ifdef SHEEPSHAVER
1532
1539
bool video_can_change_cursor(void)
1533
1540
{
1534
 
        return (display_type == DISPLAY_WINDOW);
 
1541
        static char driver[] = "Quartz?";
 
1542
        static int quartzok = -1;
 
1543
 
 
1544
        if (display_type != DISPLAY_WINDOW)
 
1545
                return false;
 
1546
 
 
1547
        if (quartzok < 0) {
 
1548
                if (SDL_VideoDriverName(driver, sizeof driver) == NULL || strncmp(driver, "Quartz", sizeof driver))
 
1549
                        quartzok = true;
 
1550
                else {
 
1551
                        // Quartz driver bug prevents cursor changing in SDL 1.2.11 to 1.2.14.
 
1552
                        const SDL_version *vp = SDL_Linked_Version();
 
1553
                        int version = SDL_VERSIONNUM(vp->major, vp->minor, vp->patch);
 
1554
                        quartzok = (version <= SDL_VERSIONNUM(1, 2, 10) || version >= SDL_VERSIONNUM(1, 2, 15));
 
1555
                }
 
1556
        }
 
1557
 
 
1558
        return quartzok;
1535
1559
}
1536
1560
#endif
1537
1561
 
1742
1766
                        // Mouse button
1743
1767
                        case SDL_MOUSEBUTTONDOWN: {
1744
1768
                                unsigned int button = event.button.button;
1745
 
                                if (button < 4)
1746
 
                                        ADBMouseDown(button - 1);
 
1769
                                if (button == SDL_BUTTON_LEFT)
 
1770
                                        ADBMouseDown(0);
 
1771
                                else if (button == SDL_BUTTON_RIGHT)
 
1772
                                        ADBMouseDown(1);
 
1773
                                else if (button == SDL_BUTTON_MIDDLE)
 
1774
                                        ADBMouseDown(2);
1747
1775
                                else if (button < 6) {  // Wheel mouse
1748
1776
                                        if (mouse_wheel_mode == 0) {
1749
1777
                                                int key = (button == 5) ? 0x79 : 0x74;  // Page up/down
1761
1789
                        }
1762
1790
                        case SDL_MOUSEBUTTONUP: {
1763
1791
                                unsigned int button = event.button.button;
1764
 
                                if (button < 4)
1765
 
                                        ADBMouseUp(button - 1);
 
1792
                                if (button == SDL_BUTTON_LEFT)
 
1793
                                        ADBMouseUp(0);
 
1794
                                else if (button == SDL_BUTTON_RIGHT)
 
1795
                                        ADBMouseUp(1);
 
1796
                                else if (button == SDL_BUTTON_MIDDLE)
 
1797
                                        ADBMouseUp(2);
1766
1798
                                break;
1767
1799
                        }
1768
1800
 
1846
1878
                                ADBKeyDown(0x7f);       // Power key
1847
1879
                                ADBKeyUp(0x7f);
1848
1880
                                break;
 
1881
 
 
1882
                        // Application activate/deactivate; consume the event but otherwise ignore it
 
1883
                        case SDL_ACTIVEEVENT:
 
1884
                                break;
1849
1885
                        }
1850
1886
                }
1851
1887
        }
1857
1893
 */
1858
1894
 
1859
1895
// Static display update (fixed frame rate, but incremental)
1860
 
static void update_display_static(driver_window *drv)
 
1896
static void update_display_static(driver_base *drv)
1861
1897
{
1862
1898
        // Incremental update code
1863
1899
        int wide = 0, high = 0, x1, x2, y1, y2, i, j;
1946
1982
 
1947
1983
                } else {
1948
1984
                        const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X;
 
1985
                        const int dst_bytes_per_row = drv->s->pitch;
1949
1986
 
1950
1987
                        x1 = VIDEO_MODE_X;
1951
1988
                        for (j=y1; j<=y2; j++) {
1986
2023
                                // Blit to screen surface
1987
2024
                                for (j=y1; j<=y2; j++) {
1988
2025
                                        i = j * bytes_per_row + x1 * bytes_per_pixel;
 
2026
                                        int dst_i = j * dst_bytes_per_row + x1 * bytes_per_pixel;
1989
2027
                                        memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * wide);
1990
 
                                        Screen_blit((uint8 *)drv->s->pixels + i, the_buffer + i, bytes_per_pixel * wide);
 
2028
                                        Screen_blit((uint8 *)drv->s->pixels + dst_i, the_buffer + i, bytes_per_pixel * wide);
1991
2029
                                }
1992
2030
 
1993
2031
                                // Unlock surface, if required
2003
2041
 
2004
2042
// Static display update (fixed frame rate, bounding boxes based)
2005
2043
// XXX use NQD bounding boxes to help detect dirty areas?
2006
 
static void update_display_static_bbox(driver_window *drv)
 
2044
static void update_display_static_bbox(driver_base *drv)
2007
2045
{
2008
2046
        const VIDEO_MODE &mode = drv->mode;
2009
2047
 
2021
2059
        // Update the surface from Mac screen
2022
2060
        const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
2023
2061
        const int bytes_per_pixel = bytes_per_row / VIDEO_MODE_X;
 
2062
        const int dst_bytes_per_row = drv->s->pitch;
2024
2063
        int x, y;
2025
2064
        for (y = 0; y < VIDEO_MODE_Y; y += N_PIXELS) {
2026
2065
                int h = N_PIXELS;
2035
2074
                        bool dirty = false;
2036
2075
                        for (int j = y; j < (y + h); j++) {
2037
2076
                                const int yb = j * bytes_per_row;
 
2077
                                const int dst_yb = j * dst_bytes_per_row;
2038
2078
                                if (memcmp(&the_buffer[yb + xb], &the_buffer_copy[yb + xb], xs) != 0) {
2039
2079
                                        memcpy(&the_buffer_copy[yb + xb], &the_buffer[yb + xb], xs);
2040
 
                                        Screen_blit((uint8 *)drv->s->pixels + yb + xb, the_buffer + yb + xb, xs);
 
2080
                                        Screen_blit((uint8 *)drv->s->pixels + dst_yb + xb, the_buffer + yb + xb, xs);
2041
2081
                                        dirty = true;
2042
2082
                                }
2043
2083
                        }
2101
2141
        UNLOCK_PALETTE;
2102
2142
}
2103
2143
 
 
2144
static void video_refresh_window_static(void);
 
2145
 
2104
2146
static void video_refresh_dga(void)
2105
2147
{
2106
2148
        // Quit DGA mode if requested
2107
2149
        possibly_quit_dga_mode();
 
2150
        video_refresh_window_static();
2108
2151
}
2109
2152
 
2110
2153
#ifdef ENABLE_VOSF
2156
2199
                tick_counter = 0;
2157
2200
                const VIDEO_MODE &mode = drv->mode;
2158
2201
                if ((int)VIDEO_MODE_DEPTH >= VIDEO_DEPTH_8BIT)
2159
 
                        update_display_static_bbox(static_cast<driver_window *>(drv));
 
2202
                        update_display_static_bbox(drv);
2160
2203
                else
2161
 
                        update_display_static(static_cast<driver_window *>(drv));
 
2204
                        update_display_static(drv);
2162
2205
        }
2163
2206
}
2164
2207
 
2204
2247
                SDL_FreeCursor(sdl_cursor);
2205
2248
                sdl_cursor = SDL_CreateCursor(MacCursor + 4, MacCursor + 36, 16, 16, MacCursor[2], MacCursor[3]);
2206
2249
                if (sdl_cursor) {
 
2250
                        SDL_ShowCursor(private_data == NULL || private_data->cursorVisible);
2207
2251
                        SDL_SetCursor(sdl_cursor);
2208
2252
#ifdef WIN32
2209
2253
                        // XXX Windows apparently needs an extra mouse event to
2283
2327
#ifdef SHEEPSHAVER
2284
2328
void video_set_dirty_area(int x, int y, int w, int h)
2285
2329
{
 
2330
#ifdef ENABLE_VOSF
2286
2331
        const VIDEO_MODE &mode = drv->mode;
2287
2332
        const int screen_width = VIDEO_MODE_X;
2288
2333
        const int screen_height = VIDEO_MODE_Y;
2289
2334
        const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
2290
2335
 
2291
 
#ifdef ENABLE_VOSF
2292
2336
        if (use_vosf) {
2293
2337
                vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row);
2294
2338
                return;