--- BasiliskII/src/Unix/video_vosf.h 2001/07/06 20:49:48 1.26 +++ BasiliskII/src/Unix/video_vosf.h 2005/11/21 23:38:46 1.55 @@ -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,37 +21,69 @@ #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 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 // Variables for Video on SEGV support static uint8 *the_host_buffer; // Host frame buffer in VOSF mode -static uint32 the_buffer_size; // Size of allocated the_buffer struct ScreenPageInfo { int top, bottom; // Mapping between this virtual page and Mac scanlines }; struct ScreenInfo { - uintptr memBase; // Real start address uintptr memStart; // Start address aligned to page boundary - uintptr memEnd; // Address of one-past-the-end of the screen uint32 memLength; // Length of the memory addressed by the screen pages - uint32 pageSize; // Size of a page + uintptr pageSize; // Size of a page int pageBits; // Shift count to get the page number 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 }; @@ -97,6 +129,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 @@ -131,10 +168,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 @@ -154,123 +199,151 @@ 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 mainBuffer structure + * Check if VOSF acceleration is profitable on this platform */ -static bool video_init_buffer(void) +const int VOSF_PROFITABLE_TRIES = 3; // Make 3 attempts for full screen update +const int VOSF_PROFITABLE_THRESHOLD = 16667; // 60 Hz + +static bool video_vosf_profitable(void) { - if (use_vosf) { - const uint32 page_size = getpagesize(); - const uint32 page_mask = page_size - 1; - - mainBuffer.memBase = (uintptr) the_buffer; - // Round up frame buffer base to page boundary - mainBuffer.memStart = (uintptr)((((unsigned long) the_buffer) + page_mask) & ~page_mask); - mainBuffer.memLength = the_buffer_size; - mainBuffer.memEnd = mainBuffer.memStart + mainBuffer.memLength; - - mainBuffer.pageSize = page_size; - mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; - mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); - - if (mainBuffer.dirtyPages) { - free(mainBuffer.dirtyPages); - mainBuffer.dirtyPages = NULL; + int64 durations[VOSF_PROFITABLE_TRIES]; + int mean_duration = 0; + + 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)); + addr[0] = 0; // Trigger Screen_fault_handler() } + int64 duration = GetTicks_usec() - start; + mean_duration += duration; + durations[i] = duration; - mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); + PFLAG_CLEAR_ALL; + mainBuffer.dirty = false; + if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) + return false; + } - if (mainBuffer.pageInfo) { - free(mainBuffer.pageInfo); - mainBuffer.pageInfo = NULL; - } + mean_duration /= VOSF_PROFITABLE_TRIES; + D(bug("Triggered %d screen faults in %ld usec on average\n", mainBuffer.pageCount, mean_duration)); + return (mean_duration < (VOSF_PROFITABLE_THRESHOLD * (frame_skip ? frame_skip : 1))); +} - mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); - if ((mainBuffer.dirtyPages == NULL) || (mainBuffer.pageInfo == NULL)) - return false; - - mainBuffer.dirty = false; +/* + * Initialize the VOSF system (mainBuffer structure, SIGSEGV handler) + */ - PFLAG_CLEAR_ALL; - // Safety net to insure the loops in the update routines will terminate - // See "How can we deal with array overrun conditions ?" hereunder for further details - PFLAG_CLEAR(mainBuffer.pageCount); - PFLAG_SET(mainBuffer.pageCount+1); - - uint32 a = 0; - for (int i = 0; i < mainBuffer.pageCount; i++) { - int y1 = a / VideoMonitor.mode.bytes_per_row; - if (y1 >= VideoMonitor.mode.y) - y1 = VideoMonitor.mode.y - 1; - - int y2 = (a + mainBuffer.pageSize) / VideoMonitor.mode.bytes_per_row; - if (y2 >= VideoMonitor.mode.y) - y2 = VideoMonitor.mode.y - 1; - - mainBuffer.pageInfo[i].top = y1; - mainBuffer.pageInfo[i].bottom = y2; - - a += mainBuffer.pageSize; - if (a > mainBuffer.memLength) - a = mainBuffer.memLength; - } +static bool video_vosf_init(MONITOR_INIT) +{ + 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 + mainBuffer.memStart = (((uintptr) the_buffer) + page_mask) & ~page_mask; + + // The frame buffer size shall already be aligned to page boundary (use page_extend) + mainBuffer.memLength = the_buffer_size; + + mainBuffer.pageSize = page_size; + mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); + mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; + + // The "2" more bytes requested are a safety net to insure the + // loops in the update routines will terminate. + // See "How can we deal with array overrun conditions ?" hereunder for further details. + mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); + if (mainBuffer.dirtyPages == NULL) + return false; - // We can now write-protect the frame buffer - if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) - return false; + PFLAG_CLEAR_ALL; + PFLAG_CLEAR(mainBuffer.pageCount); + PFLAG_SET(mainBuffer.pageCount+1); + + // Allocate and fill in pageInfo with start and end (inclusive) row in number of bytes + mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); + if (mainBuffer.pageInfo == NULL) + return false; + + uint32 a = 0; + for (unsigned i = 0; i < mainBuffer.pageCount; i++) { + 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; + + a += mainBuffer.pageSize; + if (a > mainBuffer.memLength) + a = mainBuffer.memLength; } + + // We can now write-protect the frame buffer + if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) + return false; + + // The frame buffer is sane, i.e. there is no write to it yet + mainBuffer.dirty = false; return true; } /* + * Deinitialize VOSF system + */ + +static void video_vosf_exit(void) +{ + if (mainBuffer.pageInfo) { + free(mainBuffer.pageInfo); + mainBuffer.pageInfo = NULL; + } + if (mainBuffer.dirtyPages) { + free(mainBuffer.dirtyPages); + mainBuffer.dirtyPages = NULL; + } +} + + +/* * Screen fault handler */ -static bool screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) +bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) { -// D(bug("screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", fault_address, fault_instruction)); const uintptr addr = (uintptr)fault_address; /* 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 * read-only back in one of the screen update_*() functions. */ - if ((addr >= mainBuffer.memStart) && (addr < mainBuffer.memEnd)) { - const int page = (addr - mainBuffer.memStart) >> mainBuffer.pageBits; - caddr_t page_ad = (caddr_t)(addr & -mainBuffer.pageSize); + if (((uintptr)addr - mainBuffer.memStart) < mainBuffer.memLength) { + const int page = ((uintptr)addr - mainBuffer.memStart) >> mainBuffer.pageBits; LOCK_VOSF; PFLAG_SET(page); - vm_protect((char *)page_ad, mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); + 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 0x%08X", addr); - if (fault_instruction != SIGSEGV_INVALID_PC) - fprintf(stderr, " [IP=0x%08X]", 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; } @@ -279,11 +352,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 @@ -317,11 +385,13 @@ There are two cases to check: than pageCount. */ -static inline void update_display_window_vosf(driver_window *drv) +static void update_display_window_vosf(VIDEO_DRV_WIN_INIT) { + VIDEO_MODE_INIT; + int page = 0; for (;;) { - const int first_page = find_next_page_set(page); + const unsigned first_page = find_next_page_set(page); if (first_page >= mainBuffer.pageCount) break; @@ -337,38 +407,27 @@ 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; } @@ -380,11 +439,48 @@ static inline void update_display_window */ #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 int first_page = find_next_page_set(page); + const unsigned first_page = find_next_page_set(page); if (first_page >= mainBuffer.pageCount) break; @@ -395,52 +491,84 @@ 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; }