#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include <X11/extensions/Xsp.h>
#include <SDL.h>
#include <SDL_syswm.h>
#include "display.h"
#include "gfx.h"
#include "ppu.h"
+#include "sdlv.h"
#define DIE(format, ...) do { \
fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
abort(); \
} while (0);
-static SDL_Surface *screen;
+struct gui GUI;
+
+SDL_Surface* screen;
static SDL_Rect windowSize, screenSize;
static bool gotWindowSize, gotScreenSize;
-/** Inside the surface, where are we drawing */
-static SDL_Rect renderArea;
-
-#ifdef MAEMO
-static void setDoubling(bool enable)
-{
- SDL_SysWMinfo wminfo;
- SDL_VERSION(&wminfo.version);
- if ( SDL_GetWMInfo(&wminfo) ) {
- Display *dpy = wminfo.info.x11.display;
- XSPSetPixelDoubling(dpy, 0, enable ? 1 : 0);
- XFlush(dpy);
- }
-}
-#endif
-
-static void centerRectangle(SDL_Rect& result, int areaW, int areaH, int w, int h)
-{
- result.x = areaW / 2 - w / 2;
- result.w = w;
- result.y = areaH / 2 - h / 2;
- result.h = h;
-}
+/** The current scaler object */
+Scaler* scaler;
static void calculateScreenSize()
{
{
screen = 0; // There's no need to free the screen surface.
GFX.Screen = 0;
-
+
free(GFX.SubScreen); GFX.SubScreen = 0;
free(GFX.ZBuffer); GFX.ZBuffer = 0;
free(GFX.SubZBuffer); GFX.SubZBuffer = 0;
+
+ delete scaler; scaler = 0;
}
static void setupVideoSurface()
{
// Real surface area.
- unsigned realWidth = IMAGE_WIDTH;
- unsigned realHeight = IMAGE_HEIGHT;
- // SDL Window/Surface size (bigger, so we can get mouse events there).
- unsigned srfWidth, srfHeight;
+ const unsigned gameWidth = IMAGE_WIDTH;
+ const unsigned gameHeight = IMAGE_HEIGHT;
#ifdef MAEMO
if ((Config.fullscreen && !gotScreenSize) ||
(!Config.fullscreen && !gotWindowSize)) {
// Do a first try, in order to get window/screen size
- screen = SDL_SetVideoMode(realWidth, realHeight, 16,
+ screen = SDL_SetVideoMode(gameWidth, gameHeight, 16,
SDL_SWSURFACE | SDL_RESIZABLE |
(Config.fullscreen ? SDL_FULLSCREEN : 0));
if (!screen) DIE("SDL_SetVideoMode: %s", SDL_GetError());
calculateScreenSize();
}
if (Config.fullscreen) {
- srfWidth = screenSize.w;
- srfHeight = screenSize.h;
+ GUI.Width = screenSize.w;
+ GUI.Height = screenSize.h;
} else {
- srfWidth = windowSize.w;
- srfHeight = windowSize.h;
- }
-
- // By now, just assume xsp == fullscreen. This has to change.
- Config.xsp = Config.fullscreen;
- if (!Config.xsp) {
- setDoubling(false); // Before switching video modes; avoids flicker.
+ GUI.Width = windowSize.w;
+ GUI.Height = windowSize.h;
}
#else
- srfWidth = realWidth;
- srfHeight = realHeight;
+ GUI.Width = gameWidth;
+ GUI.Height = gameHeight;
+#endif
+#if CONF_EXIT_BUTTON
+ ExitBtnReset();
#endif
- screen = SDL_SetVideoMode(srfWidth, srfHeight,
+ // Safeguard
+ if (gameHeight > GUI.Height || gameWidth > GUI.Width)
+ DIE("Video is larger than window size!");
+
+ const ScalerFactory* sFactory =
+ searchForScaler(Settings.SixteenBit ? 16 : 8, gameWidth, gameHeight);
+
+ screen = SDL_SetVideoMode(GUI.Width, GUI.Height,
Settings.SixteenBit ? 16 : 8,
SDL_SWSURFACE |
(Config.fullscreen ? SDL_FULLSCREEN : 0));
SDL_ShowCursor(SDL_DISABLE);
+ scaler = sFactory->instantiate(screen, gameWidth, gameHeight);
+
// We get pitch surface values from SDL
- GFX.RealPitch = GFX.Pitch = screen->pitch;
+ GFX.RealPitch = GFX.Pitch = scaler->getDrawBufferPitch();
GFX.ZPitch = GFX.Pitch / 2; // gfx & tile.cpp depend on this, unfortunately.
GFX.PixSize = screen->format->BitsPerPixel / 8;
-
- // Ok, calculate renderArea
-#ifdef MAEMO
- if (Config.xsp) {
- setDoubling(true);
- centerRectangle(renderArea, srfWidth, srfHeight,
- realWidth * 2, realHeight * 2);
- renderArea.w /= 2;
- renderArea.h /= 2;
- } else {
- centerRectangle(renderArea, srfWidth, srfHeight, realWidth, realHeight);
- }
-#else
- centerRectangle(renderArea, srfWidth, srfHeight, realWidth, realHeight);
-#endif
- GFX.Screen = ((uint8*) screen->pixels)
- + (renderArea.x * GFX.PixSize)
- + (renderArea.y * GFX.Pitch);
+ GFX.Screen = scaler->getDrawBuffer();
GFX.SubScreen = (uint8 *) malloc(GFX.Pitch * IMAGE_HEIGHT);
GFX.ZBuffer = (uint8 *) malloc(GFX.ZPitch * IMAGE_HEIGHT);
GFX.SubZBuffer = (uint8 *) malloc(GFX.ZPitch * IMAGE_HEIGHT);
GFX.PPL = GFX.Pitch >> 1;
GFX.PPLx2 = GFX.Pitch;
- printf("Video: %dx%d (%dx%d output), %hu bits per pixel, %s %s\n",
- realWidth, realHeight,
+ scaler->getRenderedGUIArea(GUI.RenderX, GUI.RenderY, GUI.RenderW, GUI.RenderH);
+ scaler->getRatio(GUI.ScaleX, GUI.ScaleY);
+
+ printf("Video: %dx%d (%dx%d output), %hu bits per pixel, %s, %s\n",
+ gameWidth, gameHeight,
screen->w, screen->h, screen->format->BitsPerPixel,
Config.fullscreen ? "fullscreen" : "windowed",
- Config.xsp ? "with pixel doubling" : "");
+ scaler->getName());
}
-void S9xInitDisplay(int argc, const char ** argv)
+static void drawOnscreenControls()
+{
+ if (Config.touchscreenInput) {
+ S9xInputScreenChanged();
+ }
+
+ if (Config.touchscreenShow) {
+ scaler->pause();
+ SDL_FillRect(screen, NULL, 0);
+ S9xInputScreenDraw(Settings.SixteenBit ? 2 : 1,
+ screen->pixels, screen->pitch);
+ SDL_Flip(screen);
+ scaler->resume();
+ }
+}
+
+void S9xInitDisplay(int argc, char ** argv)
{
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
DIE("SDL_InitSubSystem(VIDEO): %s", SDL_GetError());
setupVideoSurface();
+ drawOnscreenControls();
}
void S9xDeinitDisplay()
void S9xVideoToggleFullscreen()
{
- Config.fullscreen = !Config.fullscreen;
freeVideoSurface();
+ Config.fullscreen = !Config.fullscreen;
setupVideoSurface();
+ drawOnscreenControls();
}
-void S9xVideoOutputFocus(bool hasFocus)
+void processVideoEvent(const SDL_Event& event)
{
- if (Config.xsp) {
- setDoubling(hasFocus);
- }
+ if (scaler)
+ scaler->filter(event);
}
// This is here for completeness, but palette mode is useless on N8x0
bool8_32 S9xInitUpdate ()
{
- if(SDL_MUSTLOCK(screen))
- {
- if(SDL_LockSurface(screen) < 0) {
- DIE("Failed to lock SDL surface: %s", SDL_GetError());
- }
- }
+ scaler->prepare();
return TRUE;
}
bool8_32 S9xDeinitUpdate (int width, int height, bool8_32 sixteenBit)
{
- if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
+ scaler->finish();
- if (Config.xsp) {
- width *= 2;
- height *= 2;
+#if CONF_EXIT_BUTTON
+ if (ExitBtnRequiresDraw()) {
+ scaler->pause();
+ ExitBtnDraw(screen);
+ scaler->resume();
}
+#endif
- SDL_UpdateRects(screen, 1, &renderArea);
-
return TRUE;
}