10 # include <X11/extensions/Xsp.h>
13 # include <X11/Xatom.h>
24 #define DIE(format, ...) do { \
25 fprintf(stderr, "Died at %s:%d: ", __FILE__, __LINE__ ); \
26 fprintf(stderr, format "\n", ## __VA_ARGS__); \
30 /* Helper functions */
32 static void centerRectangle(SDL_Rect& result, int areaW, int areaH, int w, int h)
34 result.x = areaW / 2 - w / 2;
36 result.y = areaH / 2 - h / 2;
40 /* Base scaler for stupid scalers */
41 /** Does nothing but center the image */
42 class DummyScaler : public Scaler
44 SDL_Surface * m_screen;
48 DummyScaler(SDL_Surface* screen, int w, int h)
51 centerRectangle(m_area, GUI.Width, GUI.Height, w, h);
60 class Factory : public ScalerFactory
62 const char * getName() const
67 bool canEnable(int bpp, int w, int h) const
72 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
74 return new DummyScaler(screen, w, h);
78 static const Factory factory;
80 virtual const char * getName() const
85 virtual uint8* getDrawBuffer() const
87 const int Bpp = screen->format->BitsPerPixel / 8;
88 const int pitch = screen->pitch;
89 return ((uint8*) screen->pixels)
94 virtual unsigned int getDrawBufferPitch() const
99 virtual void getRenderedGUIArea(unsigned short & x, unsigned short & y,
100 unsigned short & w, unsigned short & h) const
102 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
105 virtual int getRatio() const
110 virtual void prepare() { };
112 virtual void finish()
114 SDL_UpdateRects(m_screen, 1, &m_area);
117 virtual void pause() { };
118 virtual void resume() { };
120 const DummyScaler::Factory DummyScaler::factory;
122 /* Basic and slow software scaler */
124 class SWScaler : public Scaler
126 SDL_Surface * m_screen;
129 const int m_w, m_h, m_Bpp;
132 SWScaler(SDL_Surface* screen, int w, int h)
133 : m_screen(screen), m_w(w), m_h(h),
134 m_Bpp(m_screen->format->BitsPerPixel / 8)
136 centerRectangle(m_area, GUI.Width, GUI.Height, w * 2, h * 2);
137 m_surface = reinterpret_cast<uint8*>(malloc(w * h * m_Bpp));
145 class Factory : public ScalerFactory
147 const char * getName() const
152 bool canEnable(int bpp, int w, int h) const
154 return w * 2 < GUI.Width && h * 2 < GUI.Height;
157 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
159 return new SWScaler(screen, w, h);
163 static const Factory factory;
165 virtual const char * getName() const
167 return "software 2x scaling";
170 uint8* getDrawBuffer() const
175 unsigned int getDrawBufferPitch() const
180 void getRenderedGUIArea(unsigned short & x, unsigned short & y,
181 unsigned short & w, unsigned short & h) const
183 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
195 uint16 * src = reinterpret_cast<uint16*>(m_surface);
196 uint16 * dst = reinterpret_cast<uint16*>(
197 ((uint8*) m_screen->pixels)
199 + (m_area.y * m_screen->pitch));
200 const int src_pitch = m_w;
201 const int dst_pitch = m_screen->pitch / m_Bpp;
204 for (y = 0; y < m_h*2; y++) {
205 for (x = 0; x < m_w*2; x+=2) {
207 dst[x + 1] = src[x/2];
210 if (y&1) src += src_pitch;
213 SDL_UpdateRects(m_screen, 1, &m_area);
219 const SWScaler::Factory SWScaler::factory;
221 /* Platform specific scalers */
224 class ARMScaler : public Scaler
226 SDL_Surface * m_screen;
229 const int m_w, m_h, m_Bpp;
232 ARMScaler(SDL_Surface* screen, int w, int h)
233 : m_screen(screen), m_w(w), m_h(h),
234 m_Bpp(m_screen->format->BitsPerPixel / 8)
236 centerRectangle(m_area, GUI.Width, GUI.Height, w * 2, h * 2);
237 m_surface = reinterpret_cast<uint8*>(malloc(w * h * m_Bpp));
245 class Factory : public ScalerFactory
247 const char * getName() const
252 bool canEnable(int bpp, int w, int h) const
254 return bpp == 16 && w * 2 < GUI.Width && h * 2 < GUI.Height &&
255 w % 16 == 0 /* asm assumes w div by 16 */;
258 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
260 return new ARMScaler(screen, w, h);
264 static const Factory factory;
266 virtual const char * getName() const
268 return "software ARM 2x scaling";
271 uint8* getDrawBuffer() const
276 unsigned int getDrawBufferPitch() const
281 void getRenderedGUIArea(unsigned short & x, unsigned short & y,
282 unsigned short & w, unsigned short & h) const
284 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
296 uint16 * src = reinterpret_cast<uint16*>(m_surface);
297 uint16 * dst = reinterpret_cast<uint16*>(
298 ((uint8*) m_screen->pixels)
300 + (m_area.y * m_screen->pitch));
301 const int src_pitch = m_w;
302 const int dst_pitch = m_screen->pitch / m_Bpp;
305 for (y = 0; y < m_h*2; y++) {
308 "mov r0, %0; mov r1, %1; mov r2, %2;"
309 "stmdb r13!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,r14};"
310 "1: ldmia r1!,{r3,r4,r5,r6,r7,r8,r9,r10};"
311 "mov r14,r5,lsr #16;"
312 "mov r12,r5,lsl #16;"
313 "orr r14,r14,r14,lsl #16;"
314 "orr r12,r12,r12,lsr #16;"
315 "mov r11,r4,lsr #16;"
317 "orr r11,r11,r11,lsl #16;"
318 "orr r5,r5,r5,lsr #16;"
321 "orr r4,r4,r4,lsl #16;"
322 "orr r3,r3,r3,lsr #16;"
323 "stmia r0!,{r3,r4,r5,r11,r12,r14};"
326 "orr r3,r3,r3,lsr #16;"
327 "orr r4,r4,r4,lsl #16;"
330 "orr r5,r5,r5,lsr #16;"
331 "orr r6,r6,r6,lsl #16;"
334 "orr r7,r7,r7,lsr #16;"
335 "orr r8,r8,r8,lsl #16;"
336 "mov r12,r10,lsr #16;"
337 "mov r11,r10,lsl #16;"
338 "orr r12,r12,r12,lsl #16;"
339 "orr r11,r11,r11,lsr #16;"
340 "mov r10,r9,lsr #16;"
342 "orr r10,r10,r10,lsl #16;"
343 "orr r9,r9,r9,lsr #16;"
344 "stmia r0!,{r3,r4,r5,r6,r7,r8,r9,r10,r11,r12};"
347 "ldmia r13!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,r14};"
349 : "r" (dst), "r" (src), "r" (m_w)
350 : "r0", "r1", "r2", "r3"
353 if (y&1) src += src_pitch;
356 SDL_UpdateRects(m_screen, 1, &m_area);
362 const ARMScaler::Factory ARMScaler::factory;
368 ATOM_HILDON_NON_COMPOSITED_WINDOW = 0,
370 ATOM_NET_WM_STATE_FULLSCREEN,
371 ATOM_NET_WM_WINDOW_TYPE,
372 ATOM_NET_WM_WINDOW_TYPE_NORMAL,
373 ATOM_NET_WM_WINDOW_TYPE_DIALOG,
374 ATOM_HILDON_WM_WINDOW_TYPE_ANIMATION_ACTOR,
375 ATOM_HILDON_ANIMATION_CLIENT_READY,
376 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_SHOW,
377 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_POSITION,
378 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_ROTATION,
379 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_SCALE,
380 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_ANCHOR,
381 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_PARENT,
382 ATOM_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE,
383 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SHM,
384 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE,
385 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW,
386 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION,
387 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET,
388 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE,
389 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT,
390 ATOM_HILDON_TEXTURE_CLIENT_READY,
394 static const char * hdAtomNames[] = {
395 "_HILDON_NON_COMPOSITED_WINDOW",
397 "_NET_WM_STATE_FULLSCREEN",
398 "_NET_WM_WINDOW_TYPE",
399 "_NET_WM_WINDOW_TYPE_NORMAL",
400 "_NET_WM_WINDOW_TYPE_DIALOG",
401 "_HILDON_WM_WINDOW_TYPE_ANIMATION_ACTOR",
402 "_HILDON_ANIMATION_CLIENT_READY",
403 "_HILDON_ANIMATION_CLIENT_MESSAGE_SHOW",
404 "_HILDON_ANIMATION_CLIENT_MESSAGE_POSITION",
405 "_HILDON_ANIMATION_CLIENT_MESSAGE_ROTATION",
406 "_HILDON_ANIMATION_CLIENT_MESSAGE_SCALE",
407 "_HILDON_ANIMATION_CLIENT_MESSAGE_ANCHOR",
408 "_HILDON_ANIMATION_CLIENT_MESSAGE_PARENT",
409 "_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE",
410 "_HILDON_TEXTURE_CLIENT_MESSAGE_SHM",
411 "_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE",
412 "_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW",
413 "_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION",
414 "_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET",
415 "_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE",
416 "_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT",
417 "_HILDON_TEXTURE_CLIENT_READY",
421 static Atom hdAtomsValues[ATOM_COUNT];
422 static bool hdAtomsLoaded = false;
424 #define HDATOM(X) hdAtomsValues[ ATOM ## X ]
426 static void hildon_load_atoms(Display* display)
428 if (hdAtomsLoaded) return;
430 XInternAtoms(display, (char**)hdAtomNames, ATOM_COUNT, True, hdAtomsValues);
431 hdAtomsLoaded = true;
433 if (HDATOM(_HILDON_NON_COMPOSITED_WINDOW) == None) {
434 DIE("Hildon Desktop seems not be loaded, since %s is not defined",
435 "_HILDON_NON_COMPOSITED_WINDOW");
440 /** Enables or disables the Hildon NonCompositedWindow property */
441 static void hildon_set_non_compositing(bool enable)
443 SDL_SysWMinfo wminfo;
446 XSetWindowAttributes xattr;
450 SDL_VERSION(&wminfo.version);
451 if (!SDL_GetWMInfo(&wminfo)) return;
453 wminfo.info.x11.lock_func();
454 display = wminfo.info.x11.display;
455 xwindow = wminfo.info.x11.fswindow;
456 hildon_load_atoms(display);
460 * The basic idea behind this is to disable the override_redirect
461 * window attribute, which SDL sets, and instead use _NET_WM_STATE
462 * to tell hildon-desktop to fullscreen the app.
463 * I am not really happy with this, which should ideally be fixed
464 * at the libsdl level, but seems to work.
465 * As soon as the window is managed by Hildon-Desktop again, set for it
466 * not to be composited.
468 XUnmapWindow(display, xwindow);
469 xattr.override_redirect = False;
470 XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &xattr);
472 atom = HDATOM(_NET_WM_STATE_FULLSCREEN);
473 XChangeProperty(display, xwindow, HDATOM(_NET_WM_STATE),
474 XA_ATOM, 32, PropModeReplace,
475 (unsigned char *) &atom, 1);
477 XChangeProperty(display, xwindow, HDATOM(_HILDON_NON_COMPOSITED_WINDOW),
478 XA_INTEGER, 32, PropModeReplace,
479 (unsigned char *) &one, 1);
480 XMapWindow(display, xwindow);
482 xattr.override_redirect = True;
483 XDeleteProperty(display, xwindow,
484 HDATOM(_HILDON_NON_COMPOSITED_WINDOW));
485 XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &xattr);
488 wminfo.info.x11.unlock_func();
491 class HDScalerBase : public Scaler
493 SDL_Surface * m_screen;
495 const int m_w, m_h, m_Bpp;
496 const float ratio_x, ratio_y;
498 // SDL/X11 stuff we save for faster access.
499 SDL_SysWMinfo wminfo;
503 // Shared memory segment info.
509 /** Sends a message to hildon-desktop.
510 * This function comes mostly straight from libhildon.
512 void sendMessage(Atom message_type,
513 uint32 l0, uint32 l1, uint32 l2, uint32 l3, uint32 l4)
515 XEvent event = { 0 };
517 event.xclient.type = ClientMessage;
518 event.xclient.window = window;
519 event.xclient.message_type = message_type;
520 event.xclient.format = 32;
521 event.xclient.data.l[0] = l0;
522 event.xclient.data.l[1] = l1;
523 event.xclient.data.l[2] = l2;
524 event.xclient.data.l[3] = l3;
525 event.xclient.data.l[4] = l4;
527 XSendEvent (display, window, True,
532 /** Sends all configuration parameters for the remote texture. */
535 SDL_VERSION(&wminfo.version);
536 if (!SDL_GetWMInfo(&wminfo)) {
537 DIE("Bad SDL version!");
542 if (Config.fullscreen) {
543 parent = wminfo.info.x11.fswindow;
545 parent = wminfo.info.x11.wmwindow;
546 yoffset = 60; // Hardcode the title bar size for now.
549 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SHM),
550 (uint32) shmkey, m_w, m_h, m_Bpp, 0);
551 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT),
552 (uint32) parent, 0, 0, 0, 0);
553 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION),
554 m_area.x, yoffset + m_area.y, m_area.w, m_area.h, 0);
555 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE),
556 ratio_x * (1 << 16), ratio_y * (1 << 16), 0, 0, 0);
557 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW),
562 HDScalerBase(SDL_Surface* screen, int w, int h, float r_x, float r_y)
563 : m_screen(screen), m_w(w), m_h(h),
564 m_Bpp(m_screen->format->BitsPerPixel / 8),
565 ratio_x(r_x), ratio_y(r_y)
567 centerRectangle(m_area, GUI.Width, GUI.Height, w * r_x, h * r_y);
569 // What we're going to do:
570 // - Create a new window that we're going to manage
571 // - Set up that window as a Hildon Remote Texture
572 // - Render to that new window, instead of the SDL window ("screen").
573 // Yet another load of uglyness, but hey.
575 // Barf if this is not a known SDL version.
576 SDL_VERSION(&wminfo.version);
577 if (!SDL_GetWMInfo(&wminfo)) {
578 DIE("Bad SDL version!");
581 // Clear the SDL screen with black, just in case it gets drawn.
582 SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
584 // Get the SDL gfxdisplay (this is where events end up).
585 display = wminfo.info.x11.display;
587 // The parent window needs to be mapped, so we sync it.
588 XSync(display, True);
590 // Ensure hildon atoms are synced, and that hildon-desktop is up.
591 hildon_load_atoms(display);
593 // Create our alternative window.
594 const int blackColor = BlackPixel(display, DefaultScreen(display));
595 window = XCreateSimpleWindow(display, DefaultRootWindow(display),
596 0, 0, m_w, m_h, 0, blackColor, blackColor);
597 XStoreName(display, window, "DrNokSnes Video output window");
598 Atom atom = HDATOM(_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE);
599 XChangeProperty(display, window, HDATOM(_NET_WM_WINDOW_TYPE),
600 XA_ATOM, 32, PropModeReplace,
601 (unsigned char *) &atom, 1);
602 XSelectInput(display, window, PropertyChangeMask | StructureNotifyMask);
603 XMapWindow(display, window);
605 // Wait for "ready" property, set up by hildon-desktop after a while
606 // For now, loop here. In the future, merge with main event loop.
610 XNextEvent(display, &e);
613 if (e.xproperty.atom ==
614 HDATOM(_HILDON_TEXTURE_CLIENT_READY)) {
623 // Create a shared memory segment with hildon-desktop
624 shmkey = ftok("/usr/bin/drnoksnes", 'd'); // TODO Put rom file here
625 shmid = shmget(shmkey, m_w * m_h * m_Bpp, IPC_CREAT | 0777);
627 DIE("Failed to create shared memory");
629 shmaddr = shmat(shmid, 0, 0);
630 if (shmaddr == (void*)-1) {
631 DIE("Failed to attach shared memory");
634 // Send all configuration events to hildon-desktop
639 virtual ~HDScalerBase()
641 // Hide, unparent and deattach the remote texture
642 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW),
644 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT),
646 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SHM),
649 // Destroy our managed window and shared memory segment
650 XDestroyWindow(display, window);
651 XSync(display, True);
653 shmctl(shmid, IPC_RMID, 0);
656 virtual uint8* getDrawBuffer() const
658 return reinterpret_cast<uint8*>(shmaddr);
661 virtual unsigned int getDrawBufferPitch() const
666 virtual void getRenderedGUIArea(unsigned short & x, unsigned short & y,
667 unsigned short & w, unsigned short & h) const
669 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
672 virtual int getRatio() const
674 return ratio_y; // TODO
677 virtual void prepare()
682 virtual void finish()
684 // Send a damage event to hildon-desktop.
685 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE),
687 XSync(display, False);
690 virtual void pause() { };
691 virtual void resume() { };
694 class HDFillScaler : public HDScalerBase
696 HDFillScaler(SDL_Surface* screen, int w, int h)
697 : HDScalerBase(screen, w, h,
698 GUI.Width / (float)w, GUI.Height / (float)h)
703 class Factory : public ScalerFactory
705 const char * getName() const
710 bool canEnable(int bpp, int w, int h) const
715 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
717 return new HDFillScaler(screen, w, h-20);
721 static const Factory factory;
723 virtual const char * getName() const
725 return "hildon-desktop fill screen scaling";
728 const HDFillScaler::Factory HDFillScaler::factory;
730 class HDSquareScaler : public HDScalerBase
732 HDSquareScaler(SDL_Surface* screen, int w, int h, float ratio)
733 : HDScalerBase(screen, w, h, ratio, ratio)
738 class Factory : public ScalerFactory
740 const char * getName() const
745 bool canEnable(int bpp, int w, int h) const
750 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
752 return new HDSquareScaler(screen, w, h,
753 fminf(GUI.Width / (float)w, GUI.Height / (float)h));
757 static const Factory factory;
759 virtual const char * getName() const
761 return "hildon-desktop square screen scaling";
764 const HDSquareScaler::Factory HDSquareScaler::factory;
766 class HDDummy : public DummyScaler
768 HDDummy(SDL_Surface* screen, int w, int h)
769 : DummyScaler(screen, w, h)
771 hildon_set_non_compositing(true);
777 hildon_set_non_compositing(false);
780 class Factory : public ScalerFactory
782 const char * getName() const
787 bool canEnable(int bpp, int w, int h) const
789 return Config.fullscreen; // This makes sense only in fullscreen
792 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
794 return new HDDummy(screen, w, h);
798 static const Factory factory;
800 const char * getName() const
802 return "compositor disabled and no scaling";
805 const HDDummy::Factory HDDummy::factory;
807 class HDSW : public SWScaler
809 HDSW(SDL_Surface* screen, int w, int h)
810 : SWScaler(screen, w, h)
812 hildon_set_non_compositing(true);
818 hildon_set_non_compositing(false);
821 class Factory : public ScalerFactory
823 const char * getName() const
828 bool canEnable(int bpp, int w, int h) const
830 return Config.fullscreen; // This makes sense only in fullscreen
833 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
835 return new HDSW(screen, w, h);
839 static const Factory factory;
841 const char * getName() const
843 return "compositor disabled and software 2x scaling";
846 const HDSW::Factory HDSW::factory;
849 class HDARM : public ARMScaler
851 HDARM(SDL_Surface* screen, int w, int h)
852 : ARMScaler(screen, w, h)
854 hildon_set_non_compositing(true);
860 hildon_set_non_compositing(false);
863 class Factory : public ScalerFactory
865 const char * getName() const
870 bool canEnable(int bpp, int w, int h) const
872 return Config.fullscreen; // This makes sense only in fullscreen
875 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
877 return new HDARM(screen, w, h);
881 static const Factory factory;
883 const char * getName() const
885 return "compositor disabled and software ARM 2x scaling";
888 const HDARM::Factory HDARM::factory;
893 class XSPScaler : public Scaler
895 SDL_Surface* m_screen;
897 SDL_Rect m_real_area;
898 bool m_should_enable, m_enabled; // Try to avoid flicker.
900 static void setDoubling(bool enable)
902 SDL_SysWMinfo wminfo;
903 SDL_VERSION(&wminfo.version);
904 if ( SDL_GetWMInfo(&wminfo) ) {
905 Display *dpy = wminfo.info.x11.display;
906 XSPSetPixelDoubling(dpy, 0, enable ? 1 : 0);
911 XSPScaler(SDL_Surface* screen, int w, int h)
912 : m_screen(screen), m_should_enable(true), m_enabled(false)
914 centerRectangle(m_area, GUI.Width, GUI.Height,
917 m_real_area.x = m_area.x;
918 m_real_area.y = m_area.y;
919 m_real_area.w = m_area.w / 2;
920 m_real_area.h = m_area.h / 2;
925 if (m_enabled) setDoubling(false);
928 class Factory : public ScalerFactory
930 const char * getName() const
935 bool canEnable(int bpp, int w, int h) const
937 return w * 2 < GUI.Width && h * 2 < GUI.Height;
940 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
942 return new XSPScaler(screen, w, h);
946 static const Factory factory;
948 const char * getName() const
950 return "XSP pixel doubling";
953 uint8* getDrawBuffer() const
955 const int Bpp = screen->format->BitsPerPixel / 8;
956 const int pitch = screen->pitch;
957 return ((uint8*) screen->pixels)
959 + (m_area.y * pitch);
962 unsigned int getDrawBufferPitch() const
964 return screen->pitch;
967 void getRenderedGUIArea(unsigned short & x, unsigned short & y,
968 unsigned short & w, unsigned short & h) const
970 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
980 if (m_should_enable && !m_enabled) {
988 SDL_UpdateRects(m_screen, 1, &m_real_area);
993 m_should_enable = false;
1002 m_should_enable = true; // Will enable later
1005 const XSPScaler::Factory XSPScaler::factory;
1008 static const ScalerFactory* scalers[] = {
1009 /* More useful scalers come first */
1010 #if CONF_HD && defined(__arm__)
1011 &HDARM::factory, /* non-composited arm 2x scaling */
1014 &HDSquareScaler::factory, /* h-d assisted square scaling */
1015 &HDSW::factory, /* non-composited soft 2x scaling */
1018 &XSPScaler::factory, /* n8x0 pixel doubling */
1021 &ARMScaler::factory, /* arm 2x scaling */
1023 &SWScaler::factory, /* soft 2x scaling */
1025 &HDDummy::factory, /* non composited */
1027 &DummyScaler::factory, /* failsafe */
1028 /* The following scalers will not be automatically enabled, no matter what */
1030 &HDFillScaler::factory,
1034 /* Entry point functions */
1036 const ScalerFactory* searchForScaler(int bpp, int w, int h)
1038 const int n = sizeof(scalers) / sizeof(ScalerFactory*);
1041 if (Config.scaler && strcasecmp(Config.scaler, "help") == 0 ) {
1043 printf("Scalers list:\n");
1044 for (i = 0; i < n; i++) {
1045 printf(" %s\n", scalers[i]->getName());
1047 DIE("End of scalers list");
1048 } else if (Config.scaler && strcasecmp(Config.scaler, "auto") != 0 ) {
1049 // We prefer a specific scaler
1050 for (i = 0; i < n; i++) {
1051 if (strcasecmp(scalers[i]->getName(), Config.scaler) == 0) {
1052 if (scalers[i]->canEnable(bpp, w, h)) {
1053 // Found the scaler selected by the user, and we can use it.
1057 "Selected scaler '%s' cannot be enabled in this mode\n",
1059 break; // Fallback to another scaler.
1064 fprintf(stderr, "Selected scaler '%s' does not exist\n",
1069 // Just try them all now, in a buildtime set priority.
1070 for (i = 0; i < n; i++) {
1071 if (scalers[i]->canEnable(bpp, w, h)) {
1076 DIE("Can't use any scaler; this shouldn't happen.");