--- BasiliskII/src/Unix/video_vosf.h 2001/07/14 18:41:01 1.29 +++ BasiliskII/src/Unix/video_vosf.h 2007/12/30 08:47:34 1.61 @@ -1,7 +1,7 @@ /* * video_vosf.h - Video/graphics emulation, video on SEGV signals support * - * Basilisk II (C) 1997-2001 Christian Bauer + * Basilisk II (C) 1997-2005 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,18 +21,60 @@ #ifndef VIDEO_VOSF_H #define VIDEO_VOSF_H -// Note: this file is #include'd in video_x.cpp +// Note: this file must be #include'd only in video_x.cpp #ifdef ENABLE_VOSF -#include -#include #include "sigsegv.h" #include "vm_alloc.h" +#ifdef _WIN32 +#include "util_windows.h" +#endif -#ifdef ENABLE_MON -# include "mon.h" +// Glue for SDL and X11 support +#ifdef TEST_VOSF_PERFORMANCE +#define MONITOR_INIT /* nothing */ +#else +#ifdef USE_SDL_VIDEO +#define MONITOR_INIT SDL_monitor_desc &monitor +#define VIDEO_DRV_WIN_INIT driver_window *drv +#define VIDEO_DRV_DGA_INIT driver_fullscreen *drv +#define VIDEO_DRV_LOCK_PIXELS SDL_VIDEO_LOCK_SURFACE(drv->s) +#define VIDEO_DRV_UNLOCK_PIXELS SDL_VIDEO_UNLOCK_SURFACE(drv->s) +#define VIDEO_DRV_DEPTH drv->s->format->BitsPerPixel +#define VIDEO_DRV_WIDTH drv->s->w +#define VIDEO_DRV_HEIGHT drv->s->h +#define VIDEO_DRV_ROW_BYTES drv->s->pitch +#else +#ifdef SHEEPSHAVER +#define MONITOR_INIT /* nothing */ +#define VIDEO_DRV_WIN_INIT /* nothing */ +#define VIDEO_DRV_DGA_INIT /* nothing */ +#define VIDEO_DRV_WINDOW the_win +#define VIDEO_DRV_GC the_gc +#define VIDEO_DRV_IMAGE img +#define VIDEO_DRV_HAVE_SHM have_shm +#else +#define MONITOR_INIT X11_monitor_desc &monitor +#define VIDEO_DRV_WIN_INIT driver_window *drv +#define VIDEO_DRV_DGA_INIT driver_dga *drv +#define VIDEO_DRV_WINDOW drv->w +#define VIDEO_DRV_GC drv->gc +#define VIDEO_DRV_IMAGE drv->img +#define VIDEO_DRV_HAVE_SHM drv->have_shm +#endif +#define VIDEO_DRV_LOCK_PIXELS /* nothing */ +#define VIDEO_DRV_UNLOCK_PIXELS /* nothing */ +#define VIDEO_DRV_DEPTH VIDEO_DRV_IMAGE->depth +#define VIDEO_DRV_WIDTH VIDEO_DRV_IMAGE->width +#define VIDEO_DRV_HEIGHT VIDEO_DRV_IMAGE->height +#define VIDEO_DRV_ROW_BYTES VIDEO_DRV_IMAGE->bytes_per_line +#endif #endif +// Prototypes +static void vosf_do_set_dirty_area(uintptr first, uintptr last); +static void vosf_set_dirty_area(int x, int y, int w, int h, int screen_width, int screen_height, int bytes_per_row); + // Variables for Video on SEGV support static uint8 *the_host_buffer; // Host frame buffer in VOSF mode @@ -49,6 +91,7 @@ struct ScreenInfo { uint32 pageCount; // Number of pages allocated to the screen bool dirty; // Flag: set if the frame buffer was touched + bool very_dirty; // Flag: set if the frame buffer was completely modified (e.g. colormap changes) char * dirtyPages; // Table of flags set if page was altered ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines }; @@ -94,6 +137,11 @@ static ScreenInfo mainBuffer; #define PFLAG_CLEAR_ALL do { \ PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \ mainBuffer.dirty = false; \ + mainBuffer.very_dirty = false; \ +} while (0) + +#define PFLAG_SET_VERY_DIRTY do { \ + mainBuffer.very_dirty = true; \ } while (0) // Set the following macro definition to 1 if your system @@ -128,10 +176,18 @@ static inline int find_next_page_clear(i #endif } -#ifdef HAVE_PTHREADS +#if defined(HAVE_PTHREADS) static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) #define LOCK_VOSF pthread_mutex_lock(&vosf_lock); #define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock); +#elif defined(_WIN32) +static mutex_t vosf_lock; // Mutex to protect frame buffer (dirtyPages in fact) +#define LOCK_VOSF vosf_lock.lock(); +#define UNLOCK_VOSF vosf_lock.unlock(); +#elif defined(HAVE_SPINLOCKS) +static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact) +#define LOCK_VOSF spin_lock(&vosf_lock) +#define UNLOCK_VOSF spin_unlock(&vosf_lock) #else #define LOCK_VOSF #define UNLOCK_VOSF @@ -151,21 +207,62 @@ static int log_base_2(uint32 x) // Extend size to page boundary static uint32 page_extend(uint32 size) { - const uint32 page_size = getpagesize(); + const uint32 page_size = vm_get_page_size(); const uint32 page_mask = page_size - 1; return (size + page_mask) & ~page_mask; } /* - * Initialize the VOSF system (mainBuffer structure, SIGSEGV handler) + * Check if VOSF acceleration is profitable on this platform */ -static bool screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction); +const int VOSF_PROFITABLE_TRIES = 3; // Make 3 attempts for full screen update +const int VOSF_PROFITABLE_THRESHOLD = 16667/2; // 60 Hz (half of the quantum) + +static bool video_vosf_profitable(void) +{ + uint32 duration = 0; + const uint32 n_page_faults = mainBuffer.pageCount * VOSF_PROFITABLE_TRIES; + +#ifdef SHEEPSHAVER + const bool accel = PrefsFindBool("gfxaccel"); +#else + const bool accel = false; +#endif + + for (int i = 0; i < VOSF_PROFITABLE_TRIES; i++) { + uint64 start = GetTicks_usec(); + for (int p = 0; p < mainBuffer.pageCount; p++) { + uint8 *addr = (uint8 *)(mainBuffer.memStart + (p * mainBuffer.pageSize)); + if (accel) + vosf_do_set_dirty_area((uintptr)addr, (uintptr)addr + mainBuffer.pageSize - 1); + else + addr[0] = 0; // Trigger Screen_fault_handler() + } + uint64 elapsed = GetTicks_usec() - start; + duration += elapsed; + + PFLAG_CLEAR_ALL; + mainBuffer.dirty = false; + if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) + return false; + } + + D(bug("Triggered %d page faults in %ld usec (%.1f usec per fault)\n", n_page_faults, duration, double(duration) / double(n_page_faults))); + return ((duration / VOSF_PROFITABLE_TRIES) < (VOSF_PROFITABLE_THRESHOLD * (frame_skip ? frame_skip : 1))); +} + + +/* + * Initialize the VOSF system (mainBuffer structure, SIGSEGV handler) + */ -static bool video_vosf_init(void) +static bool video_vosf_init(MONITOR_INIT) { - const uintptr page_size = getpagesize(); + VIDEO_MODE_INIT_MONITOR; + + const uintptr page_size = vm_get_page_size(); const uintptr page_mask = page_size - 1; // Round up frame buffer base to page boundary @@ -196,13 +293,13 @@ static bool video_vosf_init(void) uint32 a = 0; for (unsigned i = 0; i < mainBuffer.pageCount; i++) { - unsigned y1 = a / VideoMonitor.mode.bytes_per_row; - if (y1 >= VideoMonitor.mode.y) - y1 = VideoMonitor.mode.y - 1; - - unsigned y2 = (a + mainBuffer.pageSize) / VideoMonitor.mode.bytes_per_row; - if (y2 >= VideoMonitor.mode.y) - y2 = VideoMonitor.mode.y - 1; + unsigned y1 = a / VIDEO_MODE_ROW_BYTES; + if (y1 >= VIDEO_MODE_Y) + y1 = VIDEO_MODE_Y - 1; + + unsigned y2 = (a + mainBuffer.pageSize) / VIDEO_MODE_ROW_BYTES; + if (y2 >= VIDEO_MODE_Y) + y2 = VIDEO_MODE_Y - 1; mainBuffer.pageInfo[i].top = y1; mainBuffer.pageInfo[i].bottom = y2; @@ -216,10 +313,6 @@ static bool video_vosf_init(void) if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) return false; - // Initialize the handler for SIGSEGV - if (!sigsegv_install_handler(screen_fault_handler)) - return false; - // The frame buffer is sane, i.e. there is no write to it yet mainBuffer.dirty = false; return true; @@ -244,13 +337,79 @@ static void video_vosf_exit(void) /* + * Update VOSF state with specified dirty area + */ + +static void vosf_do_set_dirty_area(uintptr first, uintptr last) +{ + const int first_page = (first - mainBuffer.memStart) >> mainBuffer.pageBits; + const int last_page = (last - mainBuffer.memStart) >> mainBuffer.pageBits; + uint8 *addr = (uint8 *)(first & -mainBuffer.pageSize); + for (int i = first_page; i <= last_page; i++) { + if (PFLAG_ISCLEAR(i)) { + PFLAG_SET(i); + vm_protect(addr, mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); + } + addr += mainBuffer.pageSize; + } +} + +static void vosf_set_dirty_area(int x, int y, int w, int h, int screen_width, int screen_height, int bytes_per_row) +{ + if (x < 0) { + w -= -x; + x = 0; + } + if (y < 0) { + h -= -y; + y = 0; + } + if (w <= 0 || h <= 0) + return; + if (x + w > screen_width) + w -= (x + w) - screen_width; + if (y + h > screen_height) + h -= (y + h) - screen_height; + LOCK_VOSF; + if (bytes_per_row >= screen_width) { + const int bytes_per_pixel = bytes_per_row / screen_width; + if (bytes_per_row <= mainBuffer.pageSize) { + const uintptr a0 = mainBuffer.memStart + y * bytes_per_row + x * bytes_per_pixel; + const uintptr a1 = mainBuffer.memStart + (y + h - 1) * bytes_per_row + (x + w - 1) * bytes_per_pixel; + vosf_do_set_dirty_area(a0, a1); + } else { + for (int j = y; j < y + h; j++) { + const uintptr a0 = mainBuffer.memStart + j * bytes_per_row + x * bytes_per_pixel; + const uintptr a1 = a0 + (w - 1) * bytes_per_pixel; + vosf_do_set_dirty_area(a0, a1); + } + } + } else { + const int pixels_per_byte = screen_width / bytes_per_row; + if (bytes_per_row <= mainBuffer.pageSize) { + const uintptr a0 = mainBuffer.memStart + y * bytes_per_row + x / pixels_per_byte; + const uintptr a1 = mainBuffer.memStart + (y + h - 1) * bytes_per_row + (x + w - 1) / pixels_per_byte; + vosf_do_set_dirty_area(a0, a1); + } else { + for (int j = y; j < y + h; j++) { + const uintptr a0 = mainBuffer.memStart + j * bytes_per_row + x / pixels_per_byte; + const uintptr a1 = mainBuffer.memStart + j * bytes_per_row + (x + w - 1) / pixels_per_byte; + vosf_do_set_dirty_area(a0, a1); + } + } + } + mainBuffer.dirty = true; + UNLOCK_VOSF; +} + + +/* * Screen fault handler */ -static bool screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) +bool Screen_fault_handler(sigsegv_info_t *sip) { -// D(bug("screen_fault_handler: ADDR=%p from IP=%p\n", fault_address, fault_instruction)); - const uintptr addr = (uintptr)fault_address; + const uintptr addr = (uintptr)sigsegv_get_fault_address(sip); /* Someone attempted to write to the frame buffer. Make it writeable * now so that the data could actually be written to. It will be made @@ -259,29 +418,16 @@ static bool screen_fault_handler(sigsegv if (((uintptr)addr - mainBuffer.memStart) < mainBuffer.memLength) { const int page = ((uintptr)addr - mainBuffer.memStart) >> mainBuffer.pageBits; LOCK_VOSF; - PFLAG_SET(page); - vm_protect((char *)(addr & -mainBuffer.pageSize), mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); + if (PFLAG_ISCLEAR(page)) { + PFLAG_SET(page); + vm_protect((char *)(addr & -mainBuffer.pageSize), mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); + } mainBuffer.dirty = true; UNLOCK_VOSF; return true; } /* Otherwise, we don't know how to handle the fault, let it crash */ - fprintf(stderr, "do_handle_screen_fault: unhandled address %p", fault_address); - if (fault_instruction != SIGSEGV_INVALID_PC) - fprintf(stderr, " [IP=%p]", fault_instruction); - fprintf(stderr, "\n"); -#if EMULATED_68K - uaecptr nextpc; - extern void m68k_dumpstate(uaecptr *nextpc); - m68k_dumpstate(&nextpc); -#endif - VideoQuitFullScreen(); -#ifdef ENABLE_MON - char *arg[4] = {"mon", "-m", "-r", NULL}; - mon(3, arg); - QuitEmulator(); -#endif return false; } @@ -290,11 +436,6 @@ static bool screen_fault_handler(sigsegv * Update display for Windowed mode and VOSF */ -// From video_blit.cpp -extern void (*Screen_blit)(uint8 * dest, const uint8 * source, uint32 length); -extern bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth); -extern uint32 ExpandMap[256]; - /* How can we deal with array overrun conditions ? The state of the framebuffer pages that have been touched are maintained @@ -328,8 +469,11 @@ There are two cases to check: than pageCount. */ -static inline void update_display_window_vosf(driver_window *drv) +#ifndef TEST_VOSF_PERFORMANCE +static void update_display_window_vosf(VIDEO_DRV_WIN_INIT) { + VIDEO_MODE_INIT; + int page = 0; for (;;) { const unsigned first_page = find_next_page_set(page); @@ -348,41 +492,31 @@ static inline void update_display_window const int y1 = mainBuffer.pageInfo[first_page].top; const int y2 = mainBuffer.pageInfo[page - 1].bottom; const int height = y2 - y1 + 1; - - if (VideoMonitor.mode.depth < VDEPTH_8BIT) { - // Update the_host_buffer and copy of the_buffer - const int src_bytes_per_row = VideoMonitor.mode.bytes_per_row; - const int dst_bytes_per_row = drv->img->bytes_per_line; - const int pixels_per_byte = VideoMonitor.mode.x / src_bytes_per_row; - int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; - for (j = y1; j <= y2; j++) { - Screen_blit(the_host_buffer + i2, the_buffer + i1, VideoMonitor.mode.x / pixels_per_byte); - i1 += src_bytes_per_row; - i2 += dst_bytes_per_row; - } - - } else { - - // Update the_host_buffer and copy of the_buffer - const int src_bytes_per_row = VideoMonitor.mode.bytes_per_row; - const int dst_bytes_per_row = drv->img->bytes_per_line; - const int bytes_per_pixel = src_bytes_per_row / VideoMonitor.mode.x; - int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; - for (j = y1; j <= y2; j++) { - Screen_blit(the_host_buffer + i2, the_buffer + i1, bytes_per_pixel * VideoMonitor.mode.x); - i1 += src_bytes_per_row; - i2 += dst_bytes_per_row; - } + // Update the_host_buffer + VIDEO_DRV_LOCK_PIXELS; + const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; + const int dst_bytes_per_row = VIDEO_DRV_ROW_BYTES; + int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; + for (j = y1; j <= y2; j++) { + Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); + i1 += src_bytes_per_row; + i2 += dst_bytes_per_row; } + VIDEO_DRV_UNLOCK_PIXELS; - if (drv->have_shm) - XShmPutImage(x_display, drv->w, drv->gc, drv->img, 0, y1, 0, y1, VideoMonitor.mode.x, height, 0); +#ifdef USE_SDL_VIDEO + SDL_UpdateRect(drv->s, 0, y1, VIDEO_MODE_X, height); +#else + if (VIDEO_DRV_HAVE_SHM) + XShmPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height, 0); else - XPutImage(x_display, drv->w, drv->gc, drv->img, 0, y1, 0, y1, VideoMonitor.mode.x, height); + XPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height); +#endif } mainBuffer.dirty = false; } +#endif /* @@ -390,10 +524,48 @@ static inline void update_display_window * (only in Real or Direct Addressing mode) */ +#ifndef TEST_VOSF_PERFORMANCE #if REAL_ADDRESSING || DIRECT_ADDRESSING -static inline void update_display_dga_vosf(void) +static void update_display_dga_vosf(VIDEO_DRV_DGA_INIT) { - int page = 0; + VIDEO_MODE_INIT; + + // Compute number of bytes per row, take care to virtual screens + const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; + const int dst_bytes_per_row = TrivialBytesPerRow(VIDEO_MODE_X, DepthModeForPixelDepth(VIDEO_DRV_DEPTH)); + const int scr_bytes_per_row = VIDEO_DRV_ROW_BYTES; + assert(dst_bytes_per_row <= scr_bytes_per_row); + const int scr_bytes_left = scr_bytes_per_row - dst_bytes_per_row; + + // Full screen update requested? + if (mainBuffer.very_dirty) { + PFLAG_CLEAR_ALL; + vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ); + memcpy(the_buffer_copy, the_buffer, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); + VIDEO_DRV_LOCK_PIXELS; + int i1 = 0, i2 = 0; + for (int j = 0; j < VIDEO_MODE_Y; j++) { + Screen_blit(the_host_buffer + i2, the_buffer + i1, src_bytes_per_row); + i1 += src_bytes_per_row; + i2 += scr_bytes_per_row; + } +#ifdef USE_SDL_VIDEO + SDL_UpdateRect(drv->s, 0, 0, VIDEO_MODE_X, VIDEO_MODE_Y); +#endif + VIDEO_DRV_UNLOCK_PIXELS; + return; + } + + // Setup partial blitter (use 64-pixel wide chunks) + const int n_pixels = 64; + const int n_chunks = VIDEO_MODE_X / n_pixels; + const int n_pixels_left = VIDEO_MODE_X - (n_chunks * n_pixels); + const int src_chunk_size = src_bytes_per_row / n_chunks; + const int dst_chunk_size = dst_bytes_per_row / n_chunks; + const int src_chunk_size_left = src_bytes_per_row - (n_chunks * src_chunk_size); + const int dst_chunk_size_left = dst_bytes_per_row - (n_chunks * dst_chunk_size); + + int page = 0, last_scanline = -1; for (;;) { const unsigned first_page = find_next_page_set(page); if (first_page >= mainBuffer.pageCount) @@ -406,56 +578,89 @@ static inline void update_display_dga_vo const int32 offset = first_page << mainBuffer.pageBits; const uint32 length = (page - first_page) << mainBuffer.pageBits; vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ); - - // I am sure that y2 >= y1 and depth != 1 - const int y1 = mainBuffer.pageInfo[first_page].top; - const int y2 = mainBuffer.pageInfo[page - 1].bottom; - - const int bytes_per_row = VideoMonitor.mode.bytes_per_row; - const int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; - int i, j; - - // Check for first column from left and first column - // from right that have changed - int x1 = VideoMonitor.mode.x * bytes_per_pixel - 1; - for (j = y1; j <= y2; j++) { - uint8 * const p1 = &the_buffer[j * bytes_per_row]; - uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; - for (i = 0; i < x1; i++) { - if (p1[i] != p2[i]) { - x1 = i; - break; + + // Optimized for scanlines, don't process overlapping lines again + int y1 = mainBuffer.pageInfo[first_page].top; + int y2 = mainBuffer.pageInfo[page - 1].bottom; + if (y1 <= last_scanline && ++y1 >= VIDEO_MODE_Y) + continue; + if (y2 <= last_scanline && ++y2 >= VIDEO_MODE_Y) + continue; + last_scanline = y2; + + // Update the_host_buffer and copy of the_buffer, one line at a time + int i1 = y1 * src_bytes_per_row; + int i2 = y1 * scr_bytes_per_row; +#ifdef USE_SDL_VIDEO + int bbi = 0; + SDL_Rect bb[3] = { + { VIDEO_MODE_X, y1, 0, 0 }, + { VIDEO_MODE_X, -1, 0, 0 }, + { VIDEO_MODE_X, -1, 0, 0 } + }; +#endif + VIDEO_DRV_LOCK_PIXELS; + for (int j = y1; j <= y2; j++) { + for (int i = 0; i < n_chunks; i++) { + if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size) != 0) { + memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size); + Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size); +#ifdef USE_SDL_VIDEO + const int x = i * n_pixels; + if (x < bb[bbi].x) { + if (bb[bbi].w) + bb[bbi].w += bb[bbi].x - x; + else + bb[bbi].w = n_pixels; + bb[bbi].x = x; + } + else if (x >= bb[bbi].x + bb[bbi].w) + bb[bbi].w = x + n_pixels - bb[bbi].x; +#endif } + i1 += src_chunk_size; + i2 += dst_chunk_size; } - } - x1 /= bytes_per_pixel; - - int x2 = x1 * bytes_per_pixel; - for (j = y2; j >= y1; j--) { - uint8 * const p1 = &the_buffer[j * bytes_per_row]; - uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; - for (i = VideoMonitor.mode.x * bytes_per_pixel - 1; i > x2; i--) { - if (p1[i] != p2[i]) { - x2 = i; - break; + if (src_chunk_size_left && dst_chunk_size_left) { + if (memcmp(the_buffer_copy + i1, the_buffer + i1, src_chunk_size_left) != 0) { + memcpy(the_buffer_copy + i1, the_buffer + i1, src_chunk_size_left); + Screen_blit(the_host_buffer + i2, the_buffer + i1, src_chunk_size_left); + } + i1 += src_chunk_size_left; + i2 += dst_chunk_size_left; +#ifdef USE_SDL_VIDEO + const int x = n_chunks * n_pixels; + if (x < bb[bbi].x) { + if (bb[bbi].w) + bb[bbi].w += bb[bbi].x - x; + else + bb[bbi].w = n_pixels_left; + bb[bbi].x = x; } + else if (x >= bb[bbi].x + bb[bbi].w) + bb[bbi].w = x + n_pixels_left - bb[bbi].x; +#endif } + i2 += scr_bytes_left; +#ifdef USE_SDL_VIDEO + bb[bbi].h++; + if (bb[bbi].w && (j == y1 || j == y2 - 1 || j == y2)) { + bbi++; + assert(bbi <= 3); + if (j != y2) + bb[bbi].y = j + 1; + } +#endif } - x2 /= bytes_per_pixel; - - // Update the_host_buffer and copy of the_buffer - // There should be at least one pixel to copy - const int width = x2 - x1 + 1; - i = y1 * bytes_per_row + x1 * bytes_per_pixel; - for (j = y1; j <= y2; j++) { - Screen_blit(the_host_buffer + i, the_buffer + i, bytes_per_pixel * width); - memcpy(the_buffer_copy + i, the_buffer + i, bytes_per_pixel * width); - i += bytes_per_row; - } +#ifdef USE_SDL_VIDEO + SDL_UpdateRects(drv->s, bbi, bb); +#endif + VIDEO_DRV_UNLOCK_PIXELS; } mainBuffer.dirty = false; } #endif +#endif #endif /* ENABLE_VOSF */