syscons(4): Base renderer selection on the new mode's memory model.
authorSascha Wildner <saw@online.de>
Sun, 21 Mar 2010 23:12:38 +0000 (00:12 +0100)
committerSascha Wildner <saw@online.de>
Sun, 21 Mar 2010 23:12:38 +0000 (00:12 +0100)
Remove the hack that was initializing the renderer's functions
after switching.

sys/dev/misc/syscons/scvgarndr.c
sys/dev/misc/syscons/scvidctl.c
sys/dev/misc/syscons/syscons.c
sys/dev/misc/syscons/syscons.h

index 20783a4..1b6c986 100644 (file)
@@ -57,7 +57,6 @@ static vr_draw_mouse_t                vga_txtmouse;
 #endif
 
 #ifdef SC_PIXEL_MODE
-static vr_init_t               vga_rndrinit;
 static vr_draw_border_t                vga_pxlborder_direct;
 static vr_draw_border_t                vga_pxlborder_planar;
 static vr_draw_t               vga_vgadraw_direct;
@@ -83,43 +82,47 @@ static vr_draw_border_t             vga_grborder;
 static void                    vga_nop(scr_stat *scp, ...);
 
 static sc_rndr_sw_t txtrndrsw = {
-       (vr_init_t *)vga_nop,
        vga_txtborder,
        vga_txtdraw,    
        vga_txtcursor_shape,
        vga_txtcursor,
        vga_txtblink,
-       (vr_set_mouse_t *)vga_nop,
        vga_txtmouse,
 };
-RENDERER(vga, 0, txtrndrsw, vga_set);
+RENDERER(vga, V_INFO_MM_TEXT, txtrndrsw, vga_set);
 
 #ifdef SC_PIXEL_MODE
-static sc_rndr_sw_t vgarndrsw = {
-       vga_rndrinit,
-       (vr_draw_border_t *)vga_nop,
-       (vr_draw_t *)vga_nop,
+static sc_rndr_sw_t planarrndrsw = {
+       vga_pxlborder_planar,
+       vga_vgadraw_planar,
        vga_pxlcursor_shape,
-       (vr_draw_cursor_t *)vga_nop,
-       (vr_blink_cursor_t *)vga_nop,
-       (vr_set_mouse_t *)vga_nop,
-       (vr_draw_mouse_t *)vga_nop,
+       vga_pxlcursor_planar,
+       vga_pxlblink_planar,
+       vga_pxlmouse_planar,
+};
+RENDERER(vga, V_INFO_MM_PLANAR, planarrndrsw, vga_set);
+
+static sc_rndr_sw_t directrndrsw = {
+       vga_pxlborder_direct,
+       vga_vgadraw_direct,
+       vga_pxlcursor_shape,
+       vga_pxlcursor_direct,
+       vga_pxlblink_direct,
+       vga_pxlmouse_direct,
 };
-RENDERER(vga, PIXEL_MODE, vgarndrsw, vga_set);
+RENDERER(vga, V_INFO_MM_DIRECT, directrndrsw, vga_set);
 #endif /* SC_PIXEL_MODE */
 
 #ifndef SC_NO_MODE_CHANGE
 static sc_rndr_sw_t grrndrsw = {
-       (vr_init_t *)vga_nop,
        vga_grborder,
        (vr_draw_t *)vga_nop,
        (vr_set_cursor_t *)vga_nop,
        (vr_draw_cursor_t *)vga_nop,
        (vr_blink_cursor_t *)vga_nop,
-       (vr_set_mouse_t *)vga_nop,
        (vr_draw_mouse_t *)vga_nop,
 };
-RENDERER(vga, GRAPHICS_MODE, grrndrsw, vga_set);
+RENDERER(vga, V_INFO_MM_OTHER, grrndrsw, vga_set);
 #endif /* SC_NO_MODE_CHANGE */
 
 RENDERER_MODULE(vga, vga_set);
@@ -405,24 +408,6 @@ vga_txtmouse(scr_stat *scp, int x, int y, int on)
 /* pixel (raster text) mode renderer */
 
 static void
-vga_rndrinit(scr_stat *scp)
-{
-       if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_PLANAR) {
-               scp->rndr->draw_border = vga_pxlborder_planar;
-               scp->rndr->draw = vga_vgadraw_planar;
-               scp->rndr->draw_cursor = vga_pxlcursor_planar;
-               scp->rndr->blink_cursor = vga_pxlblink_planar;
-               scp->rndr->draw_mouse = vga_pxlmouse_planar;
-       } else if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT) {
-               scp->rndr->draw_border = vga_pxlborder_direct;
-               scp->rndr->draw = vga_vgadraw_direct;
-               scp->rndr->draw_cursor = vga_pxlcursor_direct;
-               scp->rndr->blink_cursor = vga_pxlblink_direct;
-               scp->rndr->draw_mouse = vga_pxlmouse_direct;
-       }
-}
-
-static void
 vga_pxlborder_direct(scr_stat *scp, int color)
 {
        int i, x, y;
index 3ffee63..c947406 100644 (file)
@@ -103,7 +103,7 @@ sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
        return error;
     }
 
-    if (sc_render_match(scp, scp->sc->adp->va_name, 0) == NULL) {
+    if (sc_render_match(scp, scp->sc->adp->va_name, V_INFO_MM_TEXT) == NULL) {
        crit_exit();
        return ENODEV;
     }
@@ -124,6 +124,7 @@ sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
     scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
     scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE | MOUSE_VISIBLE);
     scp->mode = mode;
+    scp->model = V_INFO_MM_TEXT;
     scp->xsize = xsize;
     scp->ysize = ysize;
     scp->xoff = 0;
@@ -181,7 +182,7 @@ sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode)
        return error;
     }
 
-    if (sc_render_match(scp, scp->sc->adp->va_name, GRAPHICS_MODE) == NULL) {
+    if (sc_render_match(scp, scp->sc->adp->va_name, V_INFO_MM_OTHER) == NULL) {
        crit_exit();
        return ENODEV;
     }
@@ -190,6 +191,7 @@ sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode)
     scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE | MOUSE_HIDDEN);
     scp->status &= ~(PIXEL_MODE | MOUSE_VISIBLE);
     scp->mode = mode;
+    scp->model = V_INFO_MM_OTHER;
     /*
      * Don't change xsize and ysize; preserve the previous vty
      * and history buffers.
@@ -314,7 +316,7 @@ sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
        return error;
     }
 
-    if (sc_render_match(scp, scp->sc->adp->va_name, PIXEL_MODE) == NULL) {
+    if (sc_render_match(scp, scp->sc->adp->va_name, info.vi_mem_model) == NULL) {
        crit_exit();
        return ENODEV;
     }
@@ -337,6 +339,7 @@ sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
     prev_ysize = scp->ysize;
     scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
     scp->status &= ~(GRAPHICS_MODE | MOUSE_VISIBLE);
+    scp->model = info.vi_mem_model;
     scp->xsize = xsize;
     scp->ysize = ysize;
     scp->xoff = (scp->xpixel/8 - xsize)/2;
@@ -622,15 +625,15 @@ sc_render_remove(sc_renderer_t *rndr)
 }
 
 sc_rndr_sw_t *
-sc_render_match(scr_stat *scp, char *name, int mode)
+sc_render_match(scr_stat *scp, char *name, int model)
 {
        const sc_renderer_t **list;
        const sc_renderer_t *p;
 
        if (!LIST_EMPTY(&sc_rndr_list)) {
                LIST_FOREACH(p, &sc_rndr_list, link) {
-                       if ((strcmp(p->name, name) == 0)
-                               && (mode == p->mode)) {
+                       if ((strcmp(p->name, name) == 0) &&
+                           (model == p->model)) {
                                scp->status &=
                                    ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
                                return p->rndrsw;
@@ -639,8 +642,8 @@ sc_render_match(scr_stat *scp, char *name, int mode)
        } else {
                SET_FOREACH(list, scrndr_set) {
                        p = *list;
-                       if ((strcmp(p->name, name) == 0)
-                               && (mode == p->mode)) {
+                       if ((strcmp(p->name, name) == 0) &&
+                           (model == p->model)) {
                                scp->status &=
                                    ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
                                return p->rndrsw;
index ac00029..43cbb5d 100644 (file)
@@ -2945,12 +2945,10 @@ sc_init_emulator(scr_stat *scp, char *name)
 
     rndr = NULL;
     if (strcmp(sw->te_renderer, "*") != 0) {
-       rndr = sc_render_match(scp, sw->te_renderer,
-                              scp->status & (GRAPHICS_MODE | PIXEL_MODE));
+       rndr = sc_render_match(scp, sw->te_renderer, scp->model);
     }
     if (rndr == NULL) {
-       rndr = sc_render_match(scp, scp->sc->adp->va_name,
-                              scp->status & (GRAPHICS_MODE | PIXEL_MODE));
+       rndr = sc_render_match(scp, scp->sc->adp->va_name, scp->model);
        if (rndr == NULL)
            return ENODEV;
     }
@@ -2958,7 +2956,6 @@ sc_init_emulator(scr_stat *scp, char *name)
     if (sw == scp->tsw) {
        error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
        scp->rndr = rndr;
-       scp->rndr->init(scp);
        sc_clear_screen(scp);
        /* assert(error == 0); */
        return error;
@@ -2979,7 +2976,6 @@ sc_init_emulator(scr_stat *scp, char *name)
     scp->tsw = sw;
     scp->ts = p;
     scp->rndr = rndr;
-    scp->rndr->init(scp);
 
     /* XXX */
     (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
@@ -3350,7 +3346,6 @@ set_mode(scr_stat *scp)
 
     /* setup video hardware for the given mode */
     (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
-    scp->rndr->init(scp);
     sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
                (void *)scp->sc->adp->va_window, FALSE);
 
index 2ae752c..22bd042 100644 (file)
@@ -303,6 +303,7 @@ typedef struct scr_stat {
        uint32_t        ega_palette[16];        /* ega palette */
        u_char          border;                 /* border color */
        int             mode;                   /* mode */
+       int             model;                  /* memory model */
        pid_t           pid;                    /* pid of controlling proc */
        struct proc     *proc;                  /* proc* of controlling proc */
        struct vt_mode  smode;                  /* switch mode */
@@ -400,7 +401,6 @@ extern struct linker_set scterm_set;
                       SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
 
 /* renderer function table */
-typedef void   vr_init_t(scr_stat *scp);
 typedef void   vr_draw_border_t(scr_stat *scp, int color);
 typedef void   vr_draw_t(scr_stat *scp, int from, int count, int flip);
 typedef void   vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
@@ -411,31 +411,29 @@ typedef void      vr_set_mouse_t(scr_stat *scp);
 typedef void   vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
 
 typedef struct sc_rndr_sw {
-       vr_init_t               *init;
        vr_draw_border_t        *draw_border;
        vr_draw_t               *draw;
        vr_set_cursor_t         *set_cursor;
        vr_draw_cursor_t        *draw_cursor;
        vr_blink_cursor_t       *blink_cursor;
-       vr_set_mouse_t          *set_mouse;
        vr_draw_mouse_t         *draw_mouse;
 } sc_rndr_sw_t;
 
 typedef struct sc_renderer {
        char                    *name;
-       int                     mode;
+       int                     model;
        sc_rndr_sw_t            *rndrsw;
        LIST_ENTRY(sc_renderer) link;
 } sc_renderer_t;
 
 extern struct linker_set scrndr_set;
 
-#define RENDERER(name, mode, sw, set)                          \
-       static struct sc_renderer scrndr_##name##_##mode = {    \
-               #name, mode, &sw                                \
+#define RENDERER(name, model, sw, set)                         \
+       static struct sc_renderer scrndr_##name##_##model = {   \
+               #name, model, &sw                               \
        };                                                      \
-       DATA_SET(scrndr_set, scrndr_##name##_##mode);           \
-       DATA_SET(set, scrndr_##name##_##mode)
+       DATA_SET(scrndr_set, scrndr_##name##_##model);          \
+       DATA_SET(set, scrndr_##name##_##model)
 
 #define RENDERER_MODULE(name, set)                             \
        SET_DECLARE(set, sc_renderer_t);                        \
@@ -571,7 +569,7 @@ int         sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data,
 
 int            sc_render_add(sc_renderer_t *rndr);
 int            sc_render_remove(sc_renderer_t *rndr);
-sc_rndr_sw_t   *sc_render_match(scr_stat *scp, char *name, int mode);
+sc_rndr_sw_t   *sc_render_match(scr_stat *scp, char *name, int model);
 
 /* scvtb.c */
 void           sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows,