]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Drawing line calculation refactoring
authorToni Wilen <twilen@winuae.net>
Sat, 22 Nov 2025 08:22:29 +0000 (10:22 +0200)
committerToni Wilen <twilen@winuae.net>
Sat, 22 Nov 2025 08:22:29 +0000 (10:22 +0200)
drawing.cpp
include/drawing.h
od-win32/avioutput.cpp
od-win32/screenshot.cpp
specialmonitors.cpp

index df62b42de7b346179582154076d40d2b0e71b425..18be3b04ec888b41e11a0d71689cc31ef5cdae95 100644 (file)
@@ -71,12 +71,10 @@ static uae_u8 *xlinebuffer_genlock_start, *xlinebuffer_genlock_end;
 
 static int *amiga2aspect_line_map, *native2amiga_line_map;
 static int native2amiga_line_map_height;
-static uae_u8 **row_map;
 static uae_u8 *row_map_genlock_buffer;
 static uae_u8 row_tmp8[MAX_PIXELS_PER_LINE * 32 / 8];
 static uae_u8 row_tmp8g[MAX_PIXELS_PER_LINE * 32 / 8];
 static int max_drawn_amiga_line;
-uae_u8 **row_map_genlock;
 uae_u8 *row_map_color_burst_buffer;
 
 static uae_sem_t write_sem, read_sem;
@@ -207,18 +205,6 @@ static void read_denise_line_queue(void)
                }
        }
 
-#if 0
-       struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
-       struct vidbuffer *vb = vidinfo->inbuffer;
-       if (!vb->locked || !vb->bufmem || row_map[0] == NULL) {
-               write_log("read_denise_line_queue: buffer cleared!\n");
-       }
-       for (int i = 0; i < vb->inheight; i++) {
-               uae_u8 *p = row_map[i];
-               *p = 0x12;
-       }
-#endif
-
        atomic_inc(&rga_queue_read);
 
        uae_sem_post(&read_sem);
@@ -1286,23 +1272,15 @@ void init_row_map(void)
        struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
        struct vidbuffer *vb = vidinfo->inbuffer;
        static uae_u8 *oldbufmem;
-       static struct vidbuffer *oldvb;
        static int oldheight_alloc, oldheight, oldpitch;
        static bool oldgenlock, oldburst;
-       int i, j;
 
        if (vb->height_allocated > max_uae_height) {
                write_log(_T("Resolution too high, aborting\n"));
                abort();
        }
-       if (!row_map) {
-               row_map = xmalloc(uae_u8 *, max_uae_height + 1);
-               row_map_genlock = xmalloc(uae_u8 *, max_uae_height + 1);
-       }
 
-       if (oldbufmem && oldbufmem == vb->bufmem &&
-               oldvb == vb &&
-               oldheight_alloc == vb->height_allocated &&
+       if (oldheight_alloc == vb->height_allocated &&
                oldheight == vb->outheight &&
                oldpitch == vb->rowbytes &&
                oldgenlock == init_genlock_data &&
@@ -1319,25 +1297,6 @@ void init_row_map(void)
        if (currprefs.cs_color_burst) {
                row_map_color_burst_buffer = xcalloc(uae_u8, vb->height_allocated + 2);
        }
-       for (i = 0, j = 0; i < vb->height_allocated; i++, j += vb->rowbytes) {
-               if (i < vb->outheight) {
-                       row_map[i] = vb->bufmem + j;
-               } else {
-                       row_map[i] = row_tmp8;
-               }
-               if (init_genlock_data) {
-                       row_map_genlock[i] = row_map_genlock_buffer + vb->width_allocated * (i + 1);
-               } else {
-                       row_map_genlock[i] = NULL;
-               }
-       }
-       while (i < max_uae_height + 1) {
-               row_map[i] = row_tmp8;
-               row_map_genlock[i] = row_tmp8g;
-               i++;
-       }
-       oldvb = vb;
-       oldbufmem = vb->bufmem;
        oldheight_alloc = vb->height_allocated;
        oldheight = vb->outheight;
        oldpitch = vb->rowbytes;
@@ -1733,25 +1692,60 @@ void putpixel(uae_u8 *buf, uae_u8 *genlockbuf, int x, xcolnr c8)
        *p = c8;
 }
 
+static uae_u8 *get_row(int monid, int line)
+{
+       struct vidbuf_description *vidinfo = &adisplays[monid].gfxvidinfo;
+       // Surface allocation may be still pending due to resolution change, make sure current size is large enough
+       if (!vidinfo->inbuffer || line < 0 || line >= vidinfo->inbuffer->height_allocated) {
+               return row_tmp8;
+       }
+       if (vidinfo->inbuffer->outwidth > vidinfo->inbuffer->width_allocated) {
+               return row_tmp8;
+       }
+       if (vidinfo->inbuffer->outheight > vidinfo->inbuffer->height_allocated) {
+               return row_tmp8;
+       }
+       uae_u8 *p = vidinfo->inbuffer->bufmem + line * vidinfo->inbuffer->rowbytes;
+       return p;
+}
+uae_u8 *get_row_genlock(int monid, int line)
+{
+       struct vidbuf_description *vidinfo = &adisplays[monid].gfxvidinfo;
+
+       if (!row_map_genlock_buffer) {
+               return NULL;
+       }
+       if (!vidinfo->inbuffer || line < 0 || line >= vidinfo->inbuffer->height_allocated) {
+               return row_tmp8g;
+       }
+       if (vidinfo->inbuffer->outwidth > vidinfo->inbuffer->width_allocated) {
+               return row_tmp8g;
+       }
+       if (vidinfo->inbuffer->outheight > vidinfo->inbuffer->height_allocated) {
+               return row_tmp8g;
+       }
+       return row_map_genlock_buffer + vidinfo->inbuffer->width_allocated * (line + 1);
+}
+
 static void setxlinebuffer(int monid, int line)
 {
        struct vidbuf_description* vidinfo = &adisplays[monid].gfxvidinfo;
 
        line += thisframe_y_adjust_real;
        if (line < 0 || line >= max_uae_height) {
-               xlinebuffer = row_map[max_uae_height - 1];
+               xlinebuffer = get_row(monid, -1);
                xlinebuffer_genlock = NULL;
 
                xlinebuffer_start = xlinebuffer;
                xlinebuffer_end = xlinebuffer + (vidinfo->inbuffer->outwidth * sizeof(uae_u32));
 
        } else {
-               xlinebuffer = row_map[line];
+               xlinebuffer = get_row(monid, line);
 
                xlinebuffer_start = xlinebuffer;
                xlinebuffer_end = xlinebuffer + (vidinfo->inbuffer->outwidth * sizeof(uae_u32));
 
-               xlinebuffer_genlock = row_map_genlock[line];
+               xlinebuffer_genlock = get_row_genlock(monid, line);
                if (xlinebuffer_genlock) {
                        xlinebuffer_genlock_start = xlinebuffer_genlock;
                        xlinebuffer_genlock_end = xlinebuffer_genlock + (vidinfo->inbuffer->outwidth);
@@ -1766,8 +1760,8 @@ static uae_u8 *status_line_ptr(int monid, int line)
        int y;
 
        y = line - (vidinfo->inbuffer->outheight - TD_TOTAL_HEIGHT);
-       xlinebuffer = row_map[line];
-       xlinebuffer_genlock = row_map_genlock[line];
+       xlinebuffer = get_row(monid, line);
+       xlinebuffer_genlock = get_row_genlock(monid, line);
        return xlinebuffer;
 }
 
@@ -1786,8 +1780,8 @@ static void draw_status_line(int monid, int line, int statusy)
 static void draw_debug_status_line(int monid, int line)
 {
        struct vidbuf_description *vidinfo = &adisplays[monid].gfxvidinfo;
-       xlinebuffer = row_map[line];
-       xlinebuffer_genlock = row_map_genlock[line];
+       xlinebuffer = get_row(monid, line);
+       xlinebuffer_genlock = get_row_genlock(monid, line);
 #ifdef DEBUGGER
        debug_draw(xlinebuffer, xlinebuffer_genlock, line, vidinfo->inbuffer->outwidth, vidinfo->inbuffer->outheight, xredcolors, xgreencolors, xbluecolors);
 #endif
@@ -5391,9 +5385,9 @@ static void lts_null(void)
        }
 }
 
-static void get_line(int gfx_ypos, enum nln_how how, int lol_shift_prev)
+static void get_line(int monid, int gfx_ypos, enum nln_how how, int lol_shift_prev)
 {
-       struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
+       struct vidbuf_description *vidinfo = &adisplays[monid].gfxvidinfo;
        struct vidbuffer *vb = vidinfo->inbuffer;
        int eraselines = 0;
        int yadjust = currprefs.gfx_overscanmode < OVERSCANMODE_ULTRA ? minfirstline_linear << currprefs.gfx_vresolution : 0;
@@ -5416,7 +5410,7 @@ static void get_line(int gfx_ypos, enum nln_how how, int lol_shift_prev)
                struct vidbuf_description* vidinfo = &adisplays[0].gfxvidinfo;
                int l = 0;
                while (l < vb->inheight) {
-                       uae_u8* b = row_map[l];
+                       uae_u8* b = get_row(monid, l);
                        memset(b, 0, vb->inwidth * vb->pixbytes);
                        l++;
                }
@@ -5713,12 +5707,8 @@ static void draw_denise_line(int gfx_ypos, enum nln_how how, uae_u32 linecnt, in
                buf2 = debug_buf;
        }
 
-       if (!row_map) {
-               return;
-       }
-
        if (startcycle == 0) {
-               get_line(gfx_ypos, how, denise_lol_shift_prev);
+               get_line(0, gfx_ypos, how, denise_lol_shift_prev);
 
                //write_log("# %d %d\n", gfx_ypos, vpos);
 
@@ -6788,7 +6778,7 @@ void draw_denise_border_line_fast(int gfx_ypos, enum nln_how how, struct linesta
                set_strlong();
        }
 
-       get_line(gfx_ypos, how, ls->lol_shift_prev);
+       get_line(0, gfx_ypos, how, ls->lol_shift_prev);
 
        if (!buf1 && !ls->blankedline && denise_planes > 0) {
                resolution_count[denise_res]++;
@@ -6887,7 +6877,7 @@ void draw_denise_bitplane_line_fast(int gfx_ypos, enum nln_how how, struct lines
                set_strlong();
        }
 
-       get_line(gfx_ypos, how, ls->lol_shift_prev);
+       get_line(0, gfx_ypos, how, ls->lol_shift_prev);
        
        //write_log("* %d %d\n", gfx_ypos, vpos);
 
index 7b2bc3c397c3cc9ef49ceed6849bfdc2b88a84fa..b368229c5b58762bfdf64ba4c6d26be177b6797d 100644 (file)
@@ -198,5 +198,6 @@ int gethresolution(void);
 void denise_update_reg_queue(uae_u16 reg, uae_u16 v, uae_u32 linecnt);
 void denise_store_restore_registers_queue(bool store, uae_u32 linecnt);
 void denise_clearbuffers(void);
+uae_u8 *get_row_genlock(int monid, int line);
 
 #endif /* UAE_DRAWING_H */
index 9aef4d75a38c306a15217bdde07748408c0c45a5..3f2e590fe2d504beb66419359013dd104cf752de 100644 (file)
@@ -38,6 +38,7 @@ Copyright(c) 2001 - 2002; 
 #include "zfile.h"
 #include "savestate.h"
 #include "gfxboard.h"
+#include "drawing.h"
 
 void WIN32GUI_LoadUIString(DWORD id, TCHAR *string, DWORD dwStringLen);
 
@@ -132,11 +133,10 @@ static LPBITMAPINFOHEADER lpbi;
 static PCOMPVARS pcompvars;
 
 extern bool need_genlock_data;
-extern uae_u8 **row_map_genlock;
 
 static bool usealpha(void)
 {
-       return need_genlock_data != 0 && row_map_genlock && currprefs.genlock_image && currprefs.genlock_alpha;
+       return need_genlock_data != 0 && get_row_genlock(0, 0) && currprefs.genlock_image && currprefs.genlock_alpha;
 }
 
 void avi_message (const TCHAR *format,...)
index d380f9b02760cb65e0e3215db36a7592ae10370c..5ec70f187230f1566894ed11cb2642d64119b215 100644 (file)
@@ -29,11 +29,10 @@ int screenshot_clipmode = 0;
 int screenshot_multi = 0;
 
 extern bool need_genlock_data;
-extern uae_u8 **row_map_genlock;
 
 static bool usealpha(void)
 {
-       return need_genlock_data != 0 && row_map_genlock && currprefs.genlock_image && currprefs.genlock_alpha;
+       return need_genlock_data != 0 && get_row_genlock(0, 0) && currprefs.genlock_image && currprefs.genlock_alpha;
 }
 
 static void namesplit (TCHAR *s)
index 8b6c3ea87cff86ce596788d19b86c61b456f6fa1..b9b25f269b4a4272bdf0b6db62cc795326563c70 100755 (executable)
@@ -77,7 +77,6 @@ static bool automatic;
 static int monitor;
 
 extern uae_u16 bplcon0;
-extern uae_u8 **row_map_genlock;
 
 static uae_u8 graffiti_palette[256 * 4];
 
@@ -814,7 +813,7 @@ static bool firecracker24(struct vidbuffer *src, struct vidbuffer *dst, bool dou
                if (yoff >= src->inheight)
                        continue;
                uae_u8 *line = src->bufmem + yoff * src->rowbytes;
-               uae_u8 *line_genlock = row_map_genlock[yoff];
+               uae_u8 *line_genlock = get_row_genlock(0, yoff);
                uae_u8 *dstline = dst->bufmem + (((y * 2 + oddlines) - dst->yoffset) / vdbl) * dst->rowbytes;
                uae_u8 *vramline = sm_frame_buffer + (fc24_y + oddlines) * SM_VRAM_WIDTH * SM_VRAM_BYTES + bufferoffset;
                fc24_x = 0;
@@ -1685,7 +1684,7 @@ static bool ham_e(struct vidbuffer *src, struct vidbuffer *dst, bool doublelines
                if (yoff >= src->inheight)
                        continue;
                uae_u8 *line = src->bufmem + yoff * src->rowbytes;
-               uae_u8 *line_genlock = row_map_genlock[yoff];
+               uae_u8 *line_genlock = get_row_genlock(0, yoff);
                uae_u8 *dstline = dst->bufmem + (((y * 2 + oddlines) - dst->yoffset) / vdbl) * dst->rowbytes;
 
                bool getpalette = false;
@@ -2604,7 +2603,7 @@ skip:
                bool ztoggle = false;
                uae_u8 *line = src->bufmem + yoff * src->rowbytes;
                uae_u8 *dstline = dst->bufmem + (((y * 2 + oddlines) - dst->yoffset) >> vdbl) * dst->rowbytes;
-               uae_u8 *line_genlock = row_map_genlock[yoff];
+               uae_u8 *line_genlock = get_row_genlock(0, yoff);
                int gy = (((y * 2 + oddlines) - src->yoffset + offsety - gen_yoffset) >> vdbl) * deltay / 65536;
                if (genlock_image_upsidedown)
                        gy = (genlock_image_height - 1) - gy;
@@ -3021,7 +3020,7 @@ static bool opalvision(struct vidbuffer *src, struct vidbuffer *dst, bool double
                int yoff = (((y * 2 - oddlines) - src->yoffset) / vdbl);
                if (yoff >= 0 && yoff < src->inheight) {
                        line = src->bufmem + yoff * src->rowbytes;
-                       line_genlock = row_map_genlock ? row_map_genlock[yoff] : NULL;
+                       line_genlock = get_row_genlock(0, yoff);
                        dstline = dst->bufmem + (((y * 2 - oddlines) - dst->yoffset) / vdbl) * dst->rowbytes;
                        if (y >= yimgstart) {
                                ydisp = y - yimgstart;