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 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;
231 ARMScaler(SDL_Surface* screen, int w, int h)
232 : m_screen(screen), m_w(w), m_h(h),
233 m_Bpp(m_screen->format->BitsPerPixel / 8)
235 centerRectangle(m_area, GUI.Width, GUI.Height, w * 2, h * 2);
236 m_surface = reinterpret_cast<uint8*>(malloc(w * h * m_Bpp));
244 class Factory : public ScalerFactory
246 const char * getName() const
251 bool canEnable(int bpp, int w, int h) const
253 return bpp == 16 && w * 2 < GUI.Width && h * 2 < GUI.Height &&
254 w % 16 == 0 /* asm assumes w div by 16 */;
257 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
259 return new ARMScaler(screen, w, h);
263 static const Factory factory;
265 const char * getName() const
267 return "software ARM 2x scaling";
270 uint8* getDrawBuffer() const
275 unsigned int getDrawBufferPitch() const
280 void getRenderedGUIArea(unsigned short & x, unsigned short & y,
281 unsigned short & w, unsigned short & h) const
283 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
295 uint16 * src = reinterpret_cast<uint16*>(m_surface);
296 uint16 * dst = reinterpret_cast<uint16*>(
297 ((uint8*) m_screen->pixels)
299 + (m_area.y * m_screen->pitch));
300 const int src_pitch = m_w;
301 const int dst_pitch = m_screen->pitch / m_Bpp;
304 for (y = 0; y < m_h*2; y++) {
307 "mov r0, %0; mov r1, %1; mov r2, %2;"
308 "stmdb r13!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,r14};"
309 "1: ldmia r1!,{r3,r4,r5,r6,r7,r8,r9,r10};"
310 "mov r14,r5,lsr #16;"
311 "mov r12,r5,lsl #16;"
312 "orr r14,r14,r14,lsl #16;"
313 "orr r12,r12,r12,lsr #16;"
314 "mov r11,r4,lsr #16;"
316 "orr r11,r11,r11,lsl #16;"
317 "orr r5,r5,r5,lsr #16;"
320 "orr r4,r4,r4,lsl #16;"
321 "orr r3,r3,r3,lsr #16;"
322 "stmia r0!,{r3,r4,r5,r11,r12,r14};"
325 "orr r3,r3,r3,lsr #16;"
326 "orr r4,r4,r4,lsl #16;"
329 "orr r5,r5,r5,lsr #16;"
330 "orr r6,r6,r6,lsl #16;"
333 "orr r7,r7,r7,lsr #16;"
334 "orr r8,r8,r8,lsl #16;"
335 "mov r12,r10,lsr #16;"
336 "mov r11,r10,lsl #16;"
337 "orr r12,r12,r12,lsl #16;"
338 "orr r11,r11,r11,lsr #16;"
339 "mov r10,r9,lsr #16;"
341 "orr r10,r10,r10,lsl #16;"
342 "orr r9,r9,r9,lsr #16;"
343 "stmia r0!,{r3,r4,r5,r6,r7,r8,r9,r10,r11,r12};"
346 "ldmia r13!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,r14};"
348 : "r" (dst), "r" (src), "r" (m_w)
349 : "r0", "r1", "r2", "r3"
352 if (y&1) src += src_pitch;
355 SDL_UpdateRects(m_screen, 1, &m_area);
361 const ARMScaler::Factory ARMScaler::factory;
367 ATOM_HILDON_NON_COMPOSITED_WINDOW = 0,
369 ATOM_NET_WM_STATE_FULLSCREEN,
370 ATOM_NET_WM_WINDOW_TYPE,
371 ATOM_NET_WM_WINDOW_TYPE_NORMAL,
372 ATOM_NET_WM_WINDOW_TYPE_DIALOG,
373 ATOM_HILDON_WM_WINDOW_TYPE_ANIMATION_ACTOR,
374 ATOM_HILDON_ANIMATION_CLIENT_READY,
375 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_SHOW,
376 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_POSITION,
377 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_ROTATION,
378 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_SCALE,
379 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_ANCHOR,
380 ATOM_HILDON_ANIMATION_CLIENT_MESSAGE_PARENT,
381 ATOM_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE,
382 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SHM,
383 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE,
384 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW,
385 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION,
386 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET,
387 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE,
388 ATOM_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT,
389 ATOM_HILDON_TEXTURE_CLIENT_READY,
393 static const char * hdAtomNames[] = {
394 "_HILDON_NON_COMPOSITED_WINDOW",
396 "_NET_WM_STATE_FULLSCREEN",
397 "_NET_WM_WINDOW_TYPE",
398 "_NET_WM_WINDOW_TYPE_NORMAL",
399 "_NET_WM_WINDOW_TYPE_DIALOG",
400 "_HILDON_WM_WINDOW_TYPE_ANIMATION_ACTOR",
401 "_HILDON_ANIMATION_CLIENT_READY",
402 "_HILDON_ANIMATION_CLIENT_MESSAGE_SHOW",
403 "_HILDON_ANIMATION_CLIENT_MESSAGE_POSITION",
404 "_HILDON_ANIMATION_CLIENT_MESSAGE_ROTATION",
405 "_HILDON_ANIMATION_CLIENT_MESSAGE_SCALE",
406 "_HILDON_ANIMATION_CLIENT_MESSAGE_ANCHOR",
407 "_HILDON_ANIMATION_CLIENT_MESSAGE_PARENT",
408 "_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE",
409 "_HILDON_TEXTURE_CLIENT_MESSAGE_SHM",
410 "_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE",
411 "_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW",
412 "_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION",
413 "_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET",
414 "_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE",
415 "_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT",
416 "_HILDON_TEXTURE_CLIENT_READY",
420 static Atom hdAtomsValues[ATOM_COUNT];
421 static bool hdAtomsLoaded = false;
423 #define HDATOM(X) hdAtomsValues[ ATOM ## X ]
425 static void hildon_load_atoms(Display* display)
427 if (hdAtomsLoaded) return;
429 XInternAtoms(display, (char**)hdAtomNames, ATOM_COUNT, True, hdAtomsValues);
430 hdAtomsLoaded = true;
432 if (HDATOM(_HILDON_NON_COMPOSITED_WINDOW) == None) {
433 DIE("Hildon Desktop seems not be loaded, since %s is not defined",
434 "_HILDON_NON_COMPOSITED_WINDOW");
439 /** Enables or disables the Hildon NonCompositedWindow property */
440 static void hildon_set_non_compositing(bool enable)
442 SDL_SysWMinfo wminfo;
445 XSetWindowAttributes xattr;
449 SDL_VERSION(&wminfo.version);
450 if (!SDL_GetWMInfo(&wminfo)) return;
452 wminfo.info.x11.lock_func();
453 display = wminfo.info.x11.display;
454 xwindow = wminfo.info.x11.fswindow;
455 hildon_load_atoms(display);
459 * The basic idea behind this is to disable the override_redirect
460 * window attribute, which SDL sets, and instead use _NET_WM_STATE
461 * to tell hildon-desktop to fullscreen the app.
462 * I am not really happy with this, which should ideally be fixed
463 * at the libsdl level, but seems to work.
464 * As soon as the window is managed by Hildon-Desktop again, set for it
465 * not to be composited.
467 XUnmapWindow(display, xwindow);
468 xattr.override_redirect = False;
469 XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &xattr);
471 atom = HDATOM(_NET_WM_STATE_FULLSCREEN);
472 XChangeProperty(display, xwindow, HDATOM(_NET_WM_STATE),
473 XA_ATOM, 32, PropModeReplace,
474 (unsigned char *) &atom, 1);
476 XChangeProperty(display, xwindow, HDATOM(_HILDON_NON_COMPOSITED_WINDOW),
477 XA_INTEGER, 32, PropModeReplace,
478 (unsigned char *) &one, 1);
479 XMapWindow(display, xwindow);
481 xattr.override_redirect = True;
482 XDeleteProperty(display, xwindow,
483 HDATOM(_HILDON_NON_COMPOSITED_WINDOW));
484 XChangeWindowAttributes(display, xwindow, CWOverrideRedirect, &xattr);
487 wminfo.info.x11.unlock_func();
490 class HDScalerBase : public Scaler
492 SDL_Surface * m_screen;
494 const int m_w, m_h, m_Bpp;
495 const float ratio_x, ratio_y;
497 // SDL/X11 stuff we save for faster access.
498 SDL_SysWMinfo wminfo;
502 // Shared memory segment info.
508 /** Sends a message to hildon-desktop.
509 * This function comes mostly straight from libhildon.
511 void sendMessage(Atom message_type,
512 uint32 l0, uint32 l1, uint32 l2, uint32 l3, uint32 l4)
514 XEvent event = { 0 };
516 event.xclient.type = ClientMessage;
517 event.xclient.window = window;
518 event.xclient.message_type = message_type;
519 event.xclient.format = 32;
520 event.xclient.data.l[0] = l0;
521 event.xclient.data.l[1] = l1;
522 event.xclient.data.l[2] = l2;
523 event.xclient.data.l[3] = l3;
524 event.xclient.data.l[4] = l4;
526 XSendEvent (display, window, True,
531 /** Sends all configuration parameters for the remote texture. */
534 SDL_VERSION(&wminfo.version);
535 if (!SDL_GetWMInfo(&wminfo)) {
536 DIE("Bad SDL version!");
541 if (Config.fullscreen) {
542 parent = wminfo.info.x11.fswindow;
544 parent = wminfo.info.x11.wmwindow;
545 yoffset = 60; // Hardcode the title bar size for now.
548 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SHM),
549 (uint32) shmkey, m_w, m_h, m_Bpp, 0);
550 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT),
551 (uint32) parent, 0, 0, 0, 0);
552 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION),
553 m_area.x, yoffset + m_area.y, m_area.w, m_area.h, 0);
554 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE),
555 ratio_x * (1 << 16), ratio_y * (1 << 16), 0, 0, 0);
556 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW),
561 HDScalerBase(SDL_Surface* screen, int w, int h, float r_x, float r_y)
562 : m_screen(screen), m_w(w), m_h(h),
563 m_Bpp(m_screen->format->BitsPerPixel / 8),
564 ratio_x(r_x), ratio_y(r_y)
566 centerRectangle(m_area, GUI.Width, GUI.Height, w * r_x, h * r_y);
568 // What we're going to do:
569 // - Create a new window that we're going to manage
570 // - Set up that window as a Hildon Remote Texture
571 // - Render to that new window, instead of the SDL window ("screen").
572 // Yet another load of uglyness, but hey.
574 // Barf if this is not a known SDL version.
575 SDL_VERSION(&wminfo.version);
576 if (!SDL_GetWMInfo(&wminfo)) {
577 DIE("Bad SDL version!");
580 // Clear the SDL screen with black, just in case it gets drawn.
581 SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
583 // Get the SDL gfxdisplay (this is where events end up).
584 display = wminfo.info.x11.display;
586 // The parent window needs to be mapped, so we sync it.
587 XSync(display, True);
589 // Ensure hildon atoms are synced, and that hildon-desktop is up.
590 hildon_load_atoms(display);
592 // Create our alternative window.
593 const int blackColor = BlackPixel(display, DefaultScreen(display));
594 window = XCreateSimpleWindow(display, DefaultRootWindow(display),
595 0, 0, m_w, m_h, 0, blackColor, blackColor);
596 XStoreName(display, window, "DrNokSnes Video output window");
597 Atom atom = HDATOM(_HILDON_WM_WINDOW_TYPE_REMOTE_TEXTURE);
598 XChangeProperty(display, window, HDATOM(_NET_WM_WINDOW_TYPE),
599 XA_ATOM, 32, PropModeReplace,
600 (unsigned char *) &atom, 1);
601 XSelectInput(display, window, PropertyChangeMask | StructureNotifyMask);
602 XMapWindow(display, window);
604 // Wait for "ready" property, set up by hildon-desktop after a while
605 // For now, loop here. In the future, merge with main event loop.
609 XNextEvent(display, &e);
612 if (e.xproperty.atom ==
613 HDATOM(_HILDON_TEXTURE_CLIENT_READY)) {
622 // Create a shared memory segment with hildon-desktop
623 shmkey = ftok("/usr/bin/drnoksnes", 'd'); // TODO Put rom file here
624 shmid = shmget(shmkey, m_w * m_h * m_Bpp, IPC_CREAT | 0777);
626 DIE("Failed to create shared memory");
628 shmaddr = shmat(shmid, 0, 0);
629 if (shmaddr == (void*)-1) {
630 DIE("Failed to attach shared memory");
633 // Send all configuration events to hildon-desktop
638 virtual ~HDScalerBase()
640 // Hide, unparent and deattach the remote texture
641 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SHOW),
643 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_PARENT),
645 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_SHM),
648 // Destroy our managed window and shared memory segment
649 XDestroyWindow(display, window);
650 XSync(display, True);
652 shmctl(shmid, IPC_RMID, 0);
655 virtual uint8* getDrawBuffer() const
657 return reinterpret_cast<uint8*>(shmaddr);
660 virtual unsigned int getDrawBufferPitch() const
665 virtual void getRenderedGUIArea(unsigned short & x, unsigned short & y,
666 unsigned short & w, unsigned short & h) const
668 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
671 virtual int getRatio() const
673 return ratio_y; // TODO
676 virtual void prepare()
681 virtual void finish()
683 // Send a damage event to hildon-desktop.
684 sendMessage(HDATOM(_HILDON_TEXTURE_CLIENT_MESSAGE_DAMAGE),
686 XSync(display, False);
689 virtual void pause() { };
690 virtual void resume() { };
693 class HDFillScaler : public HDScalerBase
695 HDFillScaler(SDL_Surface* screen, int w, int h)
696 : HDScalerBase(screen, w, h,
697 GUI.Width / (float)w, GUI.Height / (float)h)
702 class Factory : public ScalerFactory
704 const char * getName() const
709 bool canEnable(int bpp, int w, int h) const
714 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
716 return new HDFillScaler(screen, w, h-20);
720 static const Factory factory;
722 virtual const char * getName() const
724 return "hildon-desktop fill screen scaling";
727 const HDFillScaler::Factory HDFillScaler::factory;
729 class HDSquareScaler : public HDScalerBase
731 HDSquareScaler(SDL_Surface* screen, int w, int h, float ratio)
732 : HDScalerBase(screen, w, h, ratio, ratio)
737 class Factory : public ScalerFactory
739 const char * getName() const
744 bool canEnable(int bpp, int w, int h) const
749 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
751 return new HDSquareScaler(screen, w, h,
752 fminf(GUI.Width / (float)w, GUI.Height / (float)h));
756 static const Factory factory;
758 virtual const char * getName() const
760 return "hildon-desktop square screen scaling";
763 const HDSquareScaler::Factory HDSquareScaler::factory;
765 class HDDummy : public DummyScaler
767 HDDummy(SDL_Surface* screen, int w, int h)
768 : DummyScaler(screen, w, h)
770 hildon_set_non_compositing(true);
776 hildon_set_non_compositing(false);
779 class Factory : public ScalerFactory
781 const char * getName() const
786 bool canEnable(int bpp, int w, int h) const
788 return Config.fullscreen; // This makes sense only in fullscreen
791 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
793 return new HDDummy(screen, w, h);
797 static const Factory factory;
799 const char * getName() const
801 return "compositor disabled and no scaling";
804 const HDDummy::Factory HDDummy::factory;
806 class HDSW : public SWScaler
808 HDSW(SDL_Surface* screen, int w, int h)
809 : SWScaler(screen, w, h)
811 hildon_set_non_compositing(true);
817 hildon_set_non_compositing(false);
820 class Factory : public ScalerFactory
822 const char * getName() const
827 bool canEnable(int bpp, int w, int h) const
829 return Config.fullscreen; // This makes sense only in fullscreen
832 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
834 return new HDSW(screen, w, h);
838 static const Factory factory;
840 const char * getName() const
842 return "compositor disabled and software 2x scaling";
845 const HDSW::Factory HDSW::factory;
849 class XSPScaler : public Scaler
851 SDL_Surface* m_screen;
853 SDL_Rect m_real_area;
854 bool m_should_enable, m_enabled; // Try to avoid flicker.
856 static void setDoubling(bool enable)
858 SDL_SysWMinfo wminfo;
859 SDL_VERSION(&wminfo.version);
860 if ( SDL_GetWMInfo(&wminfo) ) {
861 Display *dpy = wminfo.info.x11.display;
862 XSPSetPixelDoubling(dpy, 0, enable ? 1 : 0);
867 XSPScaler(SDL_Surface* screen, int w, int h)
868 : m_screen(screen), m_should_enable(true), m_enabled(false)
870 centerRectangle(m_area, GUI.Width, GUI.Height,
873 m_real_area.x = m_area.x;
874 m_real_area.y = m_area.y;
875 m_real_area.w = m_area.w / 2;
876 m_real_area.h = m_area.h / 2;
881 if (m_enabled) setDoubling(false);
884 class Factory : public ScalerFactory
886 const char * getName() const
891 bool canEnable(int bpp, int w, int h) const
893 return w * 2 < GUI.Width && h * 2 < GUI.Height;
896 Scaler* instantiate(SDL_Surface* screen, int w, int h) const
898 return new XSPScaler(screen, w, h);
902 static const Factory factory;
904 const char * getName() const
906 return "XSP pixel doubling";
909 uint8* getDrawBuffer() const
911 const int Bpp = screen->format->BitsPerPixel / 8;
912 const int pitch = screen->pitch;
913 return ((uint8*) screen->pixels)
915 + (m_area.y * pitch);
918 unsigned int getDrawBufferPitch() const
920 return screen->pitch;
923 void getRenderedGUIArea(unsigned short & x, unsigned short & y,
924 unsigned short & w, unsigned short & h) const
926 x = m_area.x; y = m_area.y; w = m_area.w; h = m_area.h;
936 if (m_should_enable && !m_enabled) {
944 SDL_UpdateRects(m_screen, 1, &m_real_area);
949 m_should_enable = false;
958 m_should_enable = true; // Will enable later
961 const XSPScaler::Factory XSPScaler::factory;
964 static const ScalerFactory* scalers[] = {
965 /* More useful scalers come first */
967 &HDFillScaler::factory,
968 &HDSquareScaler::factory,
983 &DummyScaler::factory,
986 /* Entry point functions */
988 const ScalerFactory* searchForScaler(int bpp, int w, int h)
990 const int n = sizeof(scalers) / sizeof(ScalerFactory*);
993 if (Config.scaler && strcasecmp(Config.scaler, "help") == 0 ) {
995 printf("Scalers list:\n");
996 for (i = 0; i < n; i++) {
997 printf(" %s\n", scalers[i]->getName());
999 DIE("End of scalers list");
1000 } else if (Config.scaler && strcasecmp(Config.scaler, "auto") != 0 ) {
1001 // We prefer a specific scaler
1002 for (i = 0; i < n; i++) {
1003 if (strcasecmp(scalers[i]->getName(), Config.scaler) == 0) {
1004 if (scalers[i]->canEnable(bpp, w, h)) {
1005 // Found the scaler selected by the user, and we can use it.
1009 "Selected scaler '%s' cannot be enabled in this mode\n",
1011 break; // Fallback to another scaler.
1016 fprintf(stderr, "Selected scaler '%s' does not exist\n",
1021 // Just try them all now, in a buildtime set priority.
1022 for (i = 0; i < n; i++) {
1023 if (scalers[i]->canEnable(bpp, w, h)) {
1028 DIE("Can't use any scaler; this shouldn't happen.");