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

Comparing SheepShaver/src/Unix/video_x.cpp (file contents):
Revision 1.45 by gbeauche, 2005-06-24T22:31:28Z vs.
Revision 1.51 by asvitkine, 2009-02-19T07:08:15Z

# Line 1 | Line 1
1   /*
2   *  video_x.cpp - Video/graphics emulation, X11 specific stuff
3   *
4 < *  SheepShaver (C) 1997-2005 Marc Hellwig and Christian Bauer
4 > *  SheepShaver (C) 1997-2008 Marc Hellwig and Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 37 | Line 37
37   #include <sys/shm.h>
38   #include <errno.h>
39   #include <pthread.h>
40 + #include <semaphore.h>
41  
42   #include <algorithm>
43  
# Line 87 | Line 88 | static pthread_attr_t redraw_thread_attr
88   static volatile bool redraw_thread_cancel;      // Flag: Cancel Redraw thread
89   static pthread_t redraw_thread;                         // Redraw thread
90  
90 static bool local_X11;                                          // Flag: X server running on local machine?
91   static volatile bool thread_stop_req = false;
92 < static volatile bool thread_stop_ack = false;   // Acknowledge for thread_stop_req
92 > static sem_t thread_stop_ack;
93 > static sem_t thread_resume_req;
94  
95 + static bool local_X11;                                          // Flag: X server running on local machine?
96   static bool has_dga = false;                            // Flag: Video DGA capable
97   static bool has_vidmode = false;                        // Flag: VidMode extension available
98  
# Line 168 | Line 170 | static int num_x_video_modes;
170   #endif
171  
172   // Mutex to protect palette
173 < #ifdef HAVE_SPINLOCKS
172 < static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED;
173 < #define LOCK_PALETTE spin_lock(&x_palette_lock)
174 < #define UNLOCK_PALETTE spin_unlock(&x_palette_lock)
175 < #elif defined(HAVE_PTHREADS)
173 > #if defined(HAVE_PTHREADS)
174   static pthread_mutex_t x_palette_lock = PTHREAD_MUTEX_INITIALIZER;
175   #define LOCK_PALETTE pthread_mutex_lock(&x_palette_lock)
176   #define UNLOCK_PALETTE pthread_mutex_unlock(&x_palette_lock)
177 + #elif defined(HAVE_SPINLOCKS)
178 + static spinlock_t x_palette_lock = SPIN_LOCK_UNLOCKED;
179 + #define LOCK_PALETTE spin_lock(&x_palette_lock)
180 + #define UNLOCK_PALETTE spin_unlock(&x_palette_lock)
181   #else
182   #define LOCK_PALETTE
183   #define UNLOCK_PALETTE
184   #endif
185  
186   // Mutex to protect frame buffer
187 < #ifdef HAVE_SPINLOCKS
186 < static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED;
187 < #define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock)
188 < #define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock)
189 < #elif defined(HAVE_PTHREADS)
187 > #if defined(HAVE_PTHREADS)
188   static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
189   #define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
190   #define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock);
191 + #elif defined(HAVE_SPINLOCKS)
192 + static spinlock_t frame_buffer_lock = SPIN_LOCK_UNLOCKED;
193 + #define LOCK_FRAME_BUFFER spin_lock(&frame_buffer_lock)
194 + #define UNLOCK_FRAME_BUFFER spin_unlock(&frame_buffer_lock)
195   #else
196   #define LOCK_FRAME_BUFFER
197   #define UNLOCK_FRAME_BUFFER
# Line 1370 | Line 1372 | bool VideoInit(void)
1372          
1373          // Check if X server runs on local machine
1374          local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0)
1375 +                 || (strncmp(XDisplayName(x_display_name), "/", 1) == 0)
1376                   || (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0);
1377      
1378          // Init keycode translation
# Line 1661 | Line 1664 | bool VideoInit(void)
1664  
1665          // Start periodic thread
1666          XSync(x_display, false);
1667 +        if (sem_init(&thread_stop_ack, 0, 0) < 0)
1668 +                return false;
1669 +        if (sem_init(&thread_resume_req, 0, 0) < 0)
1670 +                return false;
1671          Set_pthread_attr(&redraw_thread_attr, 0);
1672          redraw_thread_cancel = false;
1673          redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0);
# Line 1680 | Line 1687 | void VideoExit(void)
1687                  redraw_thread_cancel = true;
1688                  pthread_cancel(redraw_thread);
1689                  pthread_join(redraw_thread, NULL);
1690 +                sem_destroy(&thread_stop_ack);
1691 +                sem_destroy(&thread_resume_req);
1692                  redraw_thread_active = false;
1693          }
1694  
# Line 2157 | Line 2166 | int16 video_mode_change(VidLocals *csSav
2166                          csSave->savePage = ReadMacInt16(ParamPtr + csPage);
2167  
2168                          // Disable interrupts and pause redraw thread
2160                        DisableInterrupt();
2161                        thread_stop_ack = false;
2169                          thread_stop_req = true;
2170 <                        while (!thread_stop_ack) ;
2170 >                        sem_wait(&thread_stop_ack);
2171 >                        thread_stop_req = false;
2172 >                        DisableInterrupt();
2173  
2174                          /* close old display */
2175                          close_display();
# Line 2181 | Line 2190 | int16 video_mode_change(VidLocals *csSav
2190                          csSave->saveMode=VModes[cur_mode].viAppleMode;
2191  
2192                          // Enable interrupts and resume redraw thread
2184                        thread_stop_req = false;
2193                          EnableInterrupt();
2194 +                        sem_post(&thread_resume_req);
2195                          return noErr;
2196                  }
2197          }
# Line 2434 | Line 2443 | static void *redraw_func(void *arg)
2443          while (!redraw_thread_cancel) {
2444  
2445                  // Pause if requested (during video mode switches)
2446 <                while (thread_stop_req)
2447 <                        thread_stop_ack = true;
2446 >                if (thread_stop_req) {
2447 >                        sem_post(&thread_stop_ack);
2448 >                        sem_wait(&thread_resume_req);
2449 >                }
2450  
2451                  int64 delay = next - GetTicks_usec();
2452                  if (delay < -VIDEO_REFRESH_DELAY) {
# Line 2549 | Line 2560 | static void *redraw_func(void *arg)
2560          }
2561          return NULL;
2562   }
2563 +
2564 +
2565 + /*
2566 + *  Record dirty area from NQD
2567 + */
2568 +
2569 + void video_set_dirty_area(int x, int y, int w, int h)
2570 + {
2571 +        VideoInfo const & mode = VModes[cur_mode];
2572 +        const int screen_width = VIDEO_MODE_X;
2573 +        const int screen_height = VIDEO_MODE_Y;
2574 +        const int bytes_per_row = VIDEO_MODE_ROW_BYTES;
2575 +
2576 + #ifdef ENABLE_VOSF
2577 +        if (use_vosf) {
2578 +                vosf_set_dirty_area(x, y, w, h, screen_width, screen_height, bytes_per_row);
2579 +                return;
2580 +        }
2581 + #endif
2582 +
2583 +        // XXX handle dirty bounding boxes for non-VOSF modes
2584 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines