diff --git a/gtk/src/gtk_display.cpp b/gtk/src/gtk_display.cpp index 81d20e15..d9e09611 100644 --- a/gtk/src/gtk_display.cpp +++ b/gtk/src/gtk_display.cpp @@ -684,19 +684,19 @@ filter_2x (void *src, for (y = 0; y < height; y++) { uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch); - uint16 *out1 = (uint16 *) ((uint8 *) dst + (y * 2) * dst_pitch); - uint16 *out2 = (uint16 *) ((uint8 *) dst + ((y * 2) + 1) * dst_pitch); + uint16 *out = (uint16 *) ((uint8 *) dst + (y * 2) * dst_pitch); for (x = 0; x < width; x++) { uint16 pixel = *in++; - *out1++ = pixel; - *out1++ = pixel; - - *out2++ = pixel; - *out2++ = pixel; + *out++ = pixel; + *out++ = pixel; } + + memcpy ((uint8 *) dst + (y * 2 + 1) * dst_pitch, + (uint8 *) dst + (y * 2) * dst_pitch, + width * 2 * 2); } return; @@ -710,30 +710,27 @@ filter_3x (void *src, int width, int height) { - int x, y; + int x, y, z; for (y = 0; y < height; y++) { uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch); - uint16 *out1 = (uint16 *) ((uint8 *) dst + (y * 3) * dst_pitch); - uint16 *out2 = (uint16 *) ((uint8 *) dst + ((y * 3) + 1) * dst_pitch); - uint16 *out3 = (uint16 *) ((uint8 *) dst + ((y * 3) + 2) * dst_pitch); + uint16 *out = (uint16 *) ((uint8 *) dst + (y * 3) * dst_pitch); for (x = 0; x < width; x++) { uint16 pixel = *in++; - *out1++ = pixel; - *out1++ = pixel; - *out1++ = pixel; + *out++ = pixel; + *out++ = pixel; + *out++ = pixel; + } - *out2++ = pixel; - *out2++ = pixel; - *out2++ = pixel; - - *out3++ = pixel; - *out3++ = pixel; - *out3++ = pixel; + for (z = 1; z <= 2; z++) + { + memcpy ((uint8 *) dst + ((y * 3) + z) * dst_pitch, + (uint8 *) dst + ((y * 3)) * dst_pitch, + width * 2 * 3); } } @@ -748,39 +745,28 @@ filter_4x (void *src, int width, int height) { - int x, y; + int x, y, z; for (y = 0; y < height; y++) { uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch); - uint16 *out1 = (uint16 *) ((uint8 *) dst + (y * 4) * dst_pitch); - uint16 *out2 = (uint16 *) ((uint8 *) dst + ((y * 4) + 1) * dst_pitch); - uint16 *out3 = (uint16 *) ((uint8 *) dst + ((y * 4) + 2) * dst_pitch); - uint16 *out4 = (uint16 *) ((uint8 *) dst + ((y * 4) + 3) * dst_pitch); + uint16 *out = (uint16 *) ((uint8 *) dst + (y * 4) * dst_pitch); for (x = 0; x < width; x++) { uint16 pixel = *in++; - *out1++ = pixel; - *out1++ = pixel; - *out1++ = pixel; - *out1++ = pixel; + *out++ = pixel; + *out++ = pixel; + *out++ = pixel; + *out++ = pixel; + } - *out2++ = pixel; - *out2++ = pixel; - *out2++ = pixel; - *out2++ = pixel; - - *out3++ = pixel; - *out3++ = pixel; - *out3++ = pixel; - *out3++ = pixel; - - *out4++ = pixel; - *out4++ = pixel; - *out4++ = pixel; - *out4++ = pixel; + for (z = 1; z <= 3; z++) + { + memcpy ((uint8 *) dst + ((y * 4) + z) * dst_pitch, + (uint8 *) dst + (y * 4) * dst_pitch, + width * 2 * 4); } } @@ -1620,6 +1606,46 @@ S9xQueryDrivers (void) bool8 S9xDeinitUpdate (int width, int height) { + int yoffset = 0; + + if (height == SNES_HEIGHT_EXTENDED && top_level->last_height == SNES_HEIGHT) + { + top_level->last_height = height; + height = SNES_HEIGHT; + } + else + { + top_level->last_height = height; + } + top_level->last_width = width; + + if (gui_config->overscan) + { + if (height == SNES_HEIGHT) + { + yoffset = -7; + height = SNES_HEIGHT_EXTENDED; + } + if (height == SNES_HEIGHT * 2) + { + yoffset = -15; + height = SNES_HEIGHT_EXTENDED * 2; + } + } + else + { + if (height == SNES_HEIGHT_EXTENDED) + { + yoffset = 7; + height = SNES_HEIGHT; + } + if (height == SNES_HEIGHT_EXTENDED * 2) + { + yoffset = 15; + height = SNES_HEIGHT * 2; + } + } + if (!Settings.Paused #ifdef NETPLAY_SUPPORT && !NetPlay.Paused @@ -1627,16 +1653,6 @@ S9xDeinitUpdate (int width, int height) ) { - if (gui_config->overscan) - height = (height > SNES_HEIGHT_EXTENDED) ? - SNES_HEIGHT_EXTENDED * 2 : - SNES_HEIGHT_EXTENDED; - else - if (height > SNES_HEIGHT_EXTENDED) - height = 448; - else - height = 224; - if (gui_config->hires_effect == HIRES_SCALE) { S9xForceHires (GFX.Screen, @@ -1657,10 +1673,7 @@ S9xDeinitUpdate (int width, int height) GFX.Screen = driver->get_next_buffer (); } - top_level->last_width = width; - top_level->last_height = height; - - driver->update (width, height); + driver->update (width, height, yoffset); return TRUE; } diff --git a/gtk/src/gtk_display_driver.h b/gtk/src/gtk_display_driver.h index d36fd467..e869aa82 100644 --- a/gtk/src/gtk_display_driver.h +++ b/gtk/src/gtk_display_driver.h @@ -11,7 +11,7 @@ class S9xDisplayDriver virtual int init (void) = 0; virtual void deinit (void) = 0; virtual void clear_buffers (void) = 0; - virtual void update (int width, int height) = 0; + virtual void update (int width, int height, int yoffset) = 0; virtual uint16 *get_next_buffer (void) = 0; virtual uint16 *get_current_buffer (void) = 0; virtual void push_buffer (uint16 *src) = 0; @@ -26,14 +26,16 @@ class S9xDisplayDriver static const int image_size = image_width * image_height * image_bpp; static const int image_padded_size = (image_width + 8) * - (image_height + 8) * + (image_height + 8 + 30) * image_bpp; + static const int image_padded_offset = (image_width + 8) * (4 + 30) + 4; static const int scaled_size = scaled_max_width * scaled_max_height * image_bpp; static const int scaled_padded_size = (scaled_max_width + 8) * (scaled_max_height + 8) * image_bpp; + static const int scaled_padded_offset = (scaled_max_width + 8) * 4 + 4; protected: Snes9xWindow *window; diff --git a/gtk/src/gtk_display_driver_gtk.cpp b/gtk/src/gtk_display_driver_gtk.cpp index b524c348..dc33b946 100644 --- a/gtk/src/gtk_display_driver_gtk.cpp +++ b/gtk/src/gtk_display_driver_gtk.cpp @@ -17,7 +17,7 @@ S9xGTKDisplayDriver::S9xGTKDisplayDriver (Snes9xWindow *window, } void -S9xGTKDisplayDriver::update (int width, int height) +S9xGTKDisplayDriver::update (int width, int height, int yoffset) { int x, y, w, h; int c_width, c_height, final_pitch; @@ -38,6 +38,8 @@ S9xGTKDisplayDriver::update (int width, int height) int src_pitch = image_width * image_bpp; int dst_pitch = scaled_max_width * image_bpp; + src_buffer += (src_pitch * yoffset); + S9xFilter (src_buffer, src_pitch, dst_buffer, @@ -52,6 +54,7 @@ S9xGTKDisplayDriver::update (int width, int height) { final_buffer = (uint8 *) padded_buffer[0]; final_pitch = image_width * image_bpp; + final_buffer += (final_pitch * yoffset); } x = width; y = height; w = c_width; h = c_height; @@ -141,17 +144,13 @@ S9xGTKDisplayDriver::output (void *src, int S9xGTKDisplayDriver::init (void) { - int padding; GtkAllocation allocation; buffer[0] = malloc (image_padded_size); buffer[1] = malloc (scaled_padded_size); - padding = (image_padded_size - image_size) / 2; - padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); - - padding = (scaled_padded_size - scaled_size) / 2; - padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding); + padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset); + padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset); gtk_widget_get_allocation (drawing_area, &allocation); gdk_buffer_width = allocation.width; @@ -275,7 +274,6 @@ void S9xGTKDisplayDriver::push_buffer (uint16 *src) { memmove (GFX.Screen, src, image_size); - update (window->last_width, window->last_height); return; } diff --git a/gtk/src/gtk_display_driver_gtk.h b/gtk/src/gtk_display_driver_gtk.h index 9f1f225c..26d25e9d 100644 --- a/gtk/src/gtk_display_driver_gtk.h +++ b/gtk/src/gtk_display_driver_gtk.h @@ -12,7 +12,7 @@ class S9xGTKDisplayDriver : public S9xDisplayDriver int init (void); void deinit (void); void clear_buffers (void); - void update (int width, int height); + void update (int width, int height, int yoffset); uint16 *get_next_buffer (void); uint16 *get_current_buffer (void); void push_buffer (uint16 *src); diff --git a/gtk/src/gtk_display_driver_opengl.cpp b/gtk/src/gtk_display_driver_opengl.cpp index 8b5f83f6..ea6ac962 100644 --- a/gtk/src/gtk_display_driver_opengl.cpp +++ b/gtk/src/gtk_display_driver_opengl.cpp @@ -109,7 +109,7 @@ __extension__ } void -S9xOpenGLDisplayDriver::update (int width, int height) +S9xOpenGLDisplayDriver::update (int width, int height, int yoffset) { uint8 *final_buffer = NULL; int final_pitch; @@ -150,6 +150,8 @@ S9xOpenGLDisplayDriver::update (int width, int height) uint8 *dst_buffer; int dst_pitch; + src_buffer += (src_pitch * yoffset); + dst_buffer = (uint8 *) padded_buffer[1]; dst_pitch = scaled_max_width * image_bpp; final_buffer = (uint8 *) padded_buffer[1]; @@ -166,6 +168,7 @@ S9xOpenGLDisplayDriver::update (int width, int height) { final_buffer = (uint8 *) padded_buffer[0]; final_pitch = image_width * image_bpp; + final_buffer += (final_pitch * yoffset); } x = width; y = height; @@ -346,7 +349,7 @@ S9xOpenGLDisplayDriver::clear_buffers (void) memset (buffer[0], 0, image_padded_size); memset (buffer[1], 0, scaled_padded_size); -/* glPixelStorei (GL_UNPACK_ROW_LENGTH, scaled_max_width); + glPixelStorei (GL_UNPACK_ROW_LENGTH, scaled_max_width); glTexSubImage2D (tex_target, 0, 0, @@ -355,7 +358,7 @@ S9xOpenGLDisplayDriver::clear_buffers (void) scaled_max_height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, - buffer[1]); */ + buffer[1]); return; } @@ -825,7 +828,6 @@ S9xOpenGLDisplayDriver::init_glx (void) int S9xOpenGLDisplayDriver::init (void) { - int padding; initialized = 0; if (!init_glx ()) @@ -838,18 +840,13 @@ S9xOpenGLDisplayDriver::init (void) return -1; } - /* Create two system buffers to avoid DMA contention */ - buffer[0] = malloc (image_padded_size); buffer[1] = malloc (scaled_padded_size); clear_buffers (); - padding = (image_padded_size - image_size) / 2; - padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); - - padding = (scaled_padded_size - scaled_size) / 2; - padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding); + padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset); + padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset); GFX.Screen = (uint16 *) padded_buffer[0]; GFX.Pitch = image_width * image_bpp; @@ -925,7 +922,6 @@ void S9xOpenGLDisplayDriver::push_buffer (uint16 *src) { memmove (padded_buffer[0], src, image_size); - update (window->last_width, window->last_height); return; } diff --git a/gtk/src/gtk_display_driver_opengl.h b/gtk/src/gtk_display_driver_opengl.h index eda8ec9d..3e506426 100644 --- a/gtk/src/gtk_display_driver_opengl.h +++ b/gtk/src/gtk_display_driver_opengl.h @@ -80,7 +80,7 @@ class S9xOpenGLDisplayDriver : public S9xDisplayDriver int init (void); void deinit (void); void clear_buffers (void); - void update (int width, int height); + void update (int width, int height, int yoffset); uint16 *get_next_buffer (void); uint16 *get_current_buffer (void); void push_buffer (uint16 *src); diff --git a/gtk/src/gtk_display_driver_xv.cpp b/gtk/src/gtk_display_driver_xv.cpp index f2a96ea7..8d4b6f93 100644 --- a/gtk/src/gtk_display_driver_xv.cpp +++ b/gtk/src/gtk_display_driver_xv.cpp @@ -87,7 +87,7 @@ S9xXVDisplayDriver::create_window (int width, int height) } void -S9xXVDisplayDriver::update (int width, int height) +S9xXVDisplayDriver::update (int width, int height, int yoffset) { int current_width, current_height, final_pitch; uint8 *final_buffer; @@ -119,6 +119,8 @@ S9xXVDisplayDriver::update (int width, int height) int src_pitch = image_width * image_bpp; int dst_pitch = scaled_max_width * image_bpp; + src_buffer += (src_pitch * yoffset); + S9xFilter (src_buffer, src_pitch, dst_buffer, @@ -133,6 +135,7 @@ S9xXVDisplayDriver::update (int width, int height) { final_buffer = (uint8 *) padded_buffer[0]; final_pitch = image_width * image_bpp; + final_buffer += (final_pitch * yoffset); } update_image_size (width, height); @@ -245,7 +248,6 @@ S9xXVDisplayDriver::update_image_size (int width, int height) int S9xXVDisplayDriver::init (void) { - int padding; int depth = 0, num_formats, num_attrs, highest_formats = 0; XvImageFormatValues *formats = NULL; XvAdaptorInfo *adaptors; @@ -258,11 +260,8 @@ S9xXVDisplayDriver::init (void) buffer[0] = malloc (image_padded_size); buffer[1] = malloc (scaled_padded_size); - padding = (image_padded_size - image_size) / 2; - padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); - - padding = (scaled_padded_size - scaled_size) / 2; - padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding); + padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset); + padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset); memset (buffer[0], 0, image_padded_size); memset (buffer[1], 0, scaled_padded_size); @@ -586,7 +585,6 @@ void S9xXVDisplayDriver::push_buffer (uint16 *src) { memmove (GFX.Screen, src, image_size); - update (window->last_width, window->last_height); return; } diff --git a/gtk/src/gtk_display_driver_xv.h b/gtk/src/gtk_display_driver_xv.h index d3673e8b..6b52a558 100644 --- a/gtk/src/gtk_display_driver_xv.h +++ b/gtk/src/gtk_display_driver_xv.h @@ -19,7 +19,7 @@ class S9xXVDisplayDriver : public S9xDisplayDriver int init (void); void deinit (void); void clear_buffers (void); - void update (int width, int height); + void update (int width, int height, int yoffset); uint16 *get_next_buffer (void); uint16 *get_current_buffer (void); void push_buffer (uint16 *src);