Overscan issues.

This commit is contained in:
Brandon Wright 2018-05-04 17:12:22 -05:00
parent 0a6931f1a7
commit 4cdb8f6e65
8 changed files with 98 additions and 91 deletions

View File

@ -684,19 +684,19 @@ filter_2x (void *src,
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
{ {
uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch); uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch);
uint16 *out1 = (uint16 *) ((uint8 *) dst + (y * 2) * dst_pitch); uint16 *out = (uint16 *) ((uint8 *) dst + (y * 2) * dst_pitch);
uint16 *out2 = (uint16 *) ((uint8 *) dst + ((y * 2) + 1) * dst_pitch);
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
{ {
uint16 pixel = *in++; uint16 pixel = *in++;
*out1++ = pixel; *out++ = pixel;
*out1++ = pixel; *out++ = pixel;
*out2++ = pixel;
*out2++ = pixel;
} }
memcpy ((uint8 *) dst + (y * 2 + 1) * dst_pitch,
(uint8 *) dst + (y * 2) * dst_pitch,
width * 2 * 2);
} }
return; return;
@ -710,30 +710,27 @@ filter_3x (void *src,
int width, int width,
int height) int height)
{ {
int x, y; int x, y, z;
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
{ {
uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch); uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch);
uint16 *out1 = (uint16 *) ((uint8 *) dst + (y * 3) * dst_pitch); uint16 *out = (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);
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
{ {
uint16 pixel = *in++; uint16 pixel = *in++;
*out1++ = pixel; *out++ = pixel;
*out1++ = pixel; *out++ = pixel;
*out1++ = pixel; *out++ = pixel;
}
*out2++ = pixel; for (z = 1; z <= 2; z++)
*out2++ = pixel; {
*out2++ = pixel; memcpy ((uint8 *) dst + ((y * 3) + z) * dst_pitch,
(uint8 *) dst + ((y * 3)) * dst_pitch,
*out3++ = pixel; width * 2 * 3);
*out3++ = pixel;
*out3++ = pixel;
} }
} }
@ -748,39 +745,28 @@ filter_4x (void *src,
int width, int width,
int height) int height)
{ {
int x, y; int x, y, z;
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
{ {
uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch); uint16 *in = (uint16 *) ((uint8 *) src + y * src_pitch);
uint16 *out1 = (uint16 *) ((uint8 *) dst + (y * 4) * dst_pitch); uint16 *out = (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);
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
{ {
uint16 pixel = *in++; uint16 pixel = *in++;
*out1++ = pixel; *out++ = pixel;
*out1++ = pixel; *out++ = pixel;
*out1++ = pixel; *out++ = pixel;
*out1++ = pixel; *out++ = pixel;
}
*out2++ = pixel; for (z = 1; z <= 3; z++)
*out2++ = pixel; {
*out2++ = pixel; memcpy ((uint8 *) dst + ((y * 4) + z) * dst_pitch,
*out2++ = pixel; (uint8 *) dst + (y * 4) * dst_pitch,
width * 2 * 4);
*out3++ = pixel;
*out3++ = pixel;
*out3++ = pixel;
*out3++ = pixel;
*out4++ = pixel;
*out4++ = pixel;
*out4++ = pixel;
*out4++ = pixel;
} }
} }
@ -1620,6 +1606,46 @@ S9xQueryDrivers (void)
bool8 bool8
S9xDeinitUpdate (int width, int height) 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 if (!Settings.Paused
#ifdef NETPLAY_SUPPORT #ifdef NETPLAY_SUPPORT
&& !NetPlay.Paused && !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) if (gui_config->hires_effect == HIRES_SCALE)
{ {
S9xForceHires (GFX.Screen, S9xForceHires (GFX.Screen,
@ -1657,10 +1673,7 @@ S9xDeinitUpdate (int width, int height)
GFX.Screen = driver->get_next_buffer (); GFX.Screen = driver->get_next_buffer ();
} }
top_level->last_width = width; driver->update (width, height, yoffset);
top_level->last_height = height;
driver->update (width, height);
return TRUE; return TRUE;
} }

View File

@ -11,7 +11,7 @@ class S9xDisplayDriver
virtual int init (void) = 0; virtual int init (void) = 0;
virtual void deinit (void) = 0; virtual void deinit (void) = 0;
virtual void clear_buffers (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_next_buffer (void) = 0;
virtual uint16 *get_current_buffer (void) = 0; virtual uint16 *get_current_buffer (void) = 0;
virtual void push_buffer (uint16 *src) = 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_size = image_width * image_height * image_bpp;
static const int image_padded_size = (image_width + 8) * static const int image_padded_size = (image_width + 8) *
(image_height + 8) * (image_height + 8 + 30) *
image_bpp; image_bpp;
static const int image_padded_offset = (image_width + 8) * (4 + 30) + 4;
static const int scaled_size = scaled_max_width * static const int scaled_size = scaled_max_width *
scaled_max_height * scaled_max_height *
image_bpp; image_bpp;
static const int scaled_padded_size = (scaled_max_width + 8) * static const int scaled_padded_size = (scaled_max_width + 8) *
(scaled_max_height + 8) * (scaled_max_height + 8) *
image_bpp; image_bpp;
static const int scaled_padded_offset = (scaled_max_width + 8) * 4 + 4;
protected: protected:
Snes9xWindow *window; Snes9xWindow *window;

View File

@ -17,7 +17,7 @@ S9xGTKDisplayDriver::S9xGTKDisplayDriver (Snes9xWindow *window,
} }
void void
S9xGTKDisplayDriver::update (int width, int height) S9xGTKDisplayDriver::update (int width, int height, int yoffset)
{ {
int x, y, w, h; int x, y, w, h;
int c_width, c_height, final_pitch; 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 src_pitch = image_width * image_bpp;
int dst_pitch = scaled_max_width * image_bpp; int dst_pitch = scaled_max_width * image_bpp;
src_buffer += (src_pitch * yoffset);
S9xFilter (src_buffer, S9xFilter (src_buffer,
src_pitch, src_pitch,
dst_buffer, dst_buffer,
@ -52,6 +54,7 @@ S9xGTKDisplayDriver::update (int width, int height)
{ {
final_buffer = (uint8 *) padded_buffer[0]; final_buffer = (uint8 *) padded_buffer[0];
final_pitch = image_width * image_bpp; final_pitch = image_width * image_bpp;
final_buffer += (final_pitch * yoffset);
} }
x = width; y = height; w = c_width; h = c_height; x = width; y = height; w = c_width; h = c_height;
@ -141,17 +144,13 @@ S9xGTKDisplayDriver::output (void *src,
int int
S9xGTKDisplayDriver::init (void) S9xGTKDisplayDriver::init (void)
{ {
int padding;
GtkAllocation allocation; GtkAllocation allocation;
buffer[0] = malloc (image_padded_size); buffer[0] = malloc (image_padded_size);
buffer[1] = malloc (scaled_padded_size); buffer[1] = malloc (scaled_padded_size);
padding = (image_padded_size - image_size) / 2; padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset);
padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset);
padding = (scaled_padded_size - scaled_size) / 2;
padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding);
gtk_widget_get_allocation (drawing_area, &allocation); gtk_widget_get_allocation (drawing_area, &allocation);
gdk_buffer_width = allocation.width; gdk_buffer_width = allocation.width;
@ -275,7 +274,6 @@ void
S9xGTKDisplayDriver::push_buffer (uint16 *src) S9xGTKDisplayDriver::push_buffer (uint16 *src)
{ {
memmove (GFX.Screen, src, image_size); memmove (GFX.Screen, src, image_size);
update (window->last_width, window->last_height);
return; return;
} }

View File

@ -12,7 +12,7 @@ class S9xGTKDisplayDriver : public S9xDisplayDriver
int init (void); int init (void);
void deinit (void); void deinit (void);
void clear_buffers (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_next_buffer (void);
uint16 *get_current_buffer (void); uint16 *get_current_buffer (void);
void push_buffer (uint16 *src); void push_buffer (uint16 *src);

View File

@ -109,7 +109,7 @@ __extension__
} }
void void
S9xOpenGLDisplayDriver::update (int width, int height) S9xOpenGLDisplayDriver::update (int width, int height, int yoffset)
{ {
uint8 *final_buffer = NULL; uint8 *final_buffer = NULL;
int final_pitch; int final_pitch;
@ -150,6 +150,8 @@ S9xOpenGLDisplayDriver::update (int width, int height)
uint8 *dst_buffer; uint8 *dst_buffer;
int dst_pitch; int dst_pitch;
src_buffer += (src_pitch * yoffset);
dst_buffer = (uint8 *) padded_buffer[1]; dst_buffer = (uint8 *) padded_buffer[1];
dst_pitch = scaled_max_width * image_bpp; dst_pitch = scaled_max_width * image_bpp;
final_buffer = (uint8 *) padded_buffer[1]; final_buffer = (uint8 *) padded_buffer[1];
@ -166,6 +168,7 @@ S9xOpenGLDisplayDriver::update (int width, int height)
{ {
final_buffer = (uint8 *) padded_buffer[0]; final_buffer = (uint8 *) padded_buffer[0];
final_pitch = image_width * image_bpp; final_pitch = image_width * image_bpp;
final_buffer += (final_pitch * yoffset);
} }
x = width; y = height; x = width; y = height;
@ -346,7 +349,7 @@ S9xOpenGLDisplayDriver::clear_buffers (void)
memset (buffer[0], 0, image_padded_size); memset (buffer[0], 0, image_padded_size);
memset (buffer[1], 0, scaled_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, glTexSubImage2D (tex_target,
0, 0,
0, 0,
@ -355,7 +358,7 @@ S9xOpenGLDisplayDriver::clear_buffers (void)
scaled_max_height, scaled_max_height,
GL_RGB, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5,
buffer[1]); */ buffer[1]);
return; return;
} }
@ -825,7 +828,6 @@ S9xOpenGLDisplayDriver::init_glx (void)
int int
S9xOpenGLDisplayDriver::init (void) S9xOpenGLDisplayDriver::init (void)
{ {
int padding;
initialized = 0; initialized = 0;
if (!init_glx ()) if (!init_glx ())
@ -838,18 +840,13 @@ S9xOpenGLDisplayDriver::init (void)
return -1; return -1;
} }
/* Create two system buffers to avoid DMA contention */
buffer[0] = malloc (image_padded_size); buffer[0] = malloc (image_padded_size);
buffer[1] = malloc (scaled_padded_size); buffer[1] = malloc (scaled_padded_size);
clear_buffers (); clear_buffers ();
padding = (image_padded_size - image_size) / 2; padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset);
padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset);
padding = (scaled_padded_size - scaled_size) / 2;
padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding);
GFX.Screen = (uint16 *) padded_buffer[0]; GFX.Screen = (uint16 *) padded_buffer[0];
GFX.Pitch = image_width * image_bpp; GFX.Pitch = image_width * image_bpp;
@ -925,7 +922,6 @@ void
S9xOpenGLDisplayDriver::push_buffer (uint16 *src) S9xOpenGLDisplayDriver::push_buffer (uint16 *src)
{ {
memmove (padded_buffer[0], src, image_size); memmove (padded_buffer[0], src, image_size);
update (window->last_width, window->last_height);
return; return;
} }

View File

@ -80,7 +80,7 @@ class S9xOpenGLDisplayDriver : public S9xDisplayDriver
int init (void); int init (void);
void deinit (void); void deinit (void);
void clear_buffers (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_next_buffer (void);
uint16 *get_current_buffer (void); uint16 *get_current_buffer (void);
void push_buffer (uint16 *src); void push_buffer (uint16 *src);

View File

@ -87,7 +87,7 @@ S9xXVDisplayDriver::create_window (int width, int height)
} }
void void
S9xXVDisplayDriver::update (int width, int height) S9xXVDisplayDriver::update (int width, int height, int yoffset)
{ {
int current_width, current_height, final_pitch; int current_width, current_height, final_pitch;
uint8 *final_buffer; uint8 *final_buffer;
@ -119,6 +119,8 @@ S9xXVDisplayDriver::update (int width, int height)
int src_pitch = image_width * image_bpp; int src_pitch = image_width * image_bpp;
int dst_pitch = scaled_max_width * image_bpp; int dst_pitch = scaled_max_width * image_bpp;
src_buffer += (src_pitch * yoffset);
S9xFilter (src_buffer, S9xFilter (src_buffer,
src_pitch, src_pitch,
dst_buffer, dst_buffer,
@ -133,6 +135,7 @@ S9xXVDisplayDriver::update (int width, int height)
{ {
final_buffer = (uint8 *) padded_buffer[0]; final_buffer = (uint8 *) padded_buffer[0];
final_pitch = image_width * image_bpp; final_pitch = image_width * image_bpp;
final_buffer += (final_pitch * yoffset);
} }
update_image_size (width, height); update_image_size (width, height);
@ -245,7 +248,6 @@ S9xXVDisplayDriver::update_image_size (int width, int height)
int int
S9xXVDisplayDriver::init (void) S9xXVDisplayDriver::init (void)
{ {
int padding;
int depth = 0, num_formats, num_attrs, highest_formats = 0; int depth = 0, num_formats, num_attrs, highest_formats = 0;
XvImageFormatValues *formats = NULL; XvImageFormatValues *formats = NULL;
XvAdaptorInfo *adaptors; XvAdaptorInfo *adaptors;
@ -258,11 +260,8 @@ S9xXVDisplayDriver::init (void)
buffer[0] = malloc (image_padded_size); buffer[0] = malloc (image_padded_size);
buffer[1] = malloc (scaled_padded_size); buffer[1] = malloc (scaled_padded_size);
padding = (image_padded_size - image_size) / 2; padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + image_padded_offset);
padded_buffer[0] = (void *) (((uint8 *) buffer[0]) + padding); padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + scaled_padded_offset);
padding = (scaled_padded_size - scaled_size) / 2;
padded_buffer[1] = (void *) (((uint8 *) buffer[1]) + padding);
memset (buffer[0], 0, image_padded_size); memset (buffer[0], 0, image_padded_size);
memset (buffer[1], 0, scaled_padded_size); memset (buffer[1], 0, scaled_padded_size);
@ -586,7 +585,6 @@ void
S9xXVDisplayDriver::push_buffer (uint16 *src) S9xXVDisplayDriver::push_buffer (uint16 *src)
{ {
memmove (GFX.Screen, src, image_size); memmove (GFX.Screen, src, image_size);
update (window->last_width, window->last_height);
return; return;
} }

View File

@ -19,7 +19,7 @@ class S9xXVDisplayDriver : public S9xDisplayDriver
int init (void); int init (void);
void deinit (void); void deinit (void);
void clear_buffers (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_next_buffer (void);
uint16 *get_current_buffer (void); uint16 *get_current_buffer (void);
void push_buffer (uint16 *src); void push_buffer (uint16 *src);