From: Toni Wilen Date: Sat, 1 Apr 2023 08:01:47 +0000 (+0300) Subject: Fix surface limit check. X-Git-Tag: 5.0.0~96 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=2dc6d283550ede21c3cabaabfb64e7ebddb74aab;p=francis%2Fwinuae.git Fix surface limit check. --- diff --git a/gfxboard.cpp b/gfxboard.cpp index 0388505f..a3e28411 100644 --- a/gfxboard.cpp +++ b/gfxboard.cpp @@ -712,14 +712,14 @@ void video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) if (gb->gfxboard_surface) { struct picasso_vidbuf_description *vidinfo = &picasso_vidinfo[gb->monitor_id]; if (w != gb->width_redraw || h != gb->height_redraw) { - for (int y = 0; y < vidinfo->height; y++) { + for (int y = 0; y < vidinfo->maxheight; y++) { uae_u8 *d = gb->gfxboard_surface + y * vidinfo->rowbytes; if (y < h) { - if (vidinfo->width > w) { - memset(d + w * vidinfo->pixbytes, 0, (vidinfo->width - w) * vidinfo->pixbytes); + if (vidinfo->maxwidth > w) { + memset(d + w * vidinfo->pixbytes, 0, (vidinfo->maxwidth - w) * vidinfo->pixbytes); } } else { - memset(d, 0, vidinfo->width * vidinfo->pixbytes); + memset(d, 0, vidinfo->maxwidth * vidinfo->pixbytes); } } gb->width_redraw = w; @@ -727,10 +727,10 @@ void video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) y1 = 0; y2 = h; } - for (int yy = y1; yy < y2 && yy < vidinfo->height; yy++) { + for (int yy = y1; yy < y2 && yy < vidinfo->maxheight; yy++) { uae_u8 *d = gb->gfxboard_surface + yy * vidinfo->rowbytes; uae_u8 *s = getpcembuffer32(x, y, yy); - int ww = w > vidinfo->width ? vidinfo->width : w; + int ww = w > vidinfo->maxwidth ? vidinfo->maxwidth : w; memcpy(d, s, ww * vidinfo->pixbytes); } } diff --git a/od-win32/direct3d.cpp b/od-win32/direct3d.cpp index 1101d1b4..a105e0c8 100644 --- a/od-win32/direct3d.cpp +++ b/od-win32/direct3d.cpp @@ -3760,7 +3760,7 @@ static void xD3D_unlocktexture(int monid, int y_start, int y_end) d3d->fulllocked = 0; } -static uae_u8 *xD3D_locktexture (int monid, int *pitch, int *height, int fullupdate) +static uae_u8 *xD3D_locktexture (int monid, int *pitch, int *width, int *height, int fullupdate) { struct d3dstruct *d3d = &d3ddata[monid]; D3DLOCKED_RECT lock; @@ -3823,6 +3823,8 @@ static uae_u8 *xD3D_locktexture (int monid, int *pitch, int *height, int fullupd *pitch = lock.Pitch; if (height) *height = d3d->tin_h; + if (width) + *width = d3d->tin_w; return (uae_u8*)lock.pBits; } diff --git a/od-win32/direct3d.h b/od-win32/direct3d.h index 63e5905e..559e860b 100644 --- a/od-win32/direct3d.h +++ b/od-win32/direct3d.h @@ -14,7 +14,7 @@ extern void(*D3D_refresh)(int); extern bool(*D3D_renderframe)(int, int,bool); extern void(*D3D_showframe)(int); extern void(*D3D_showframe_special)(int, int); -extern uae_u8* (*D3D_locktexture)(int, int*, int*, int); +extern uae_u8 *(*D3D_locktexture)(int, int*, int*, int*, int); extern void(*D3D_unlocktexture)(int, int, int); extern void(*D3D_flushtexture)(int, int miny, int maxy); extern void(*D3D_guimode)(int, int); @@ -24,7 +24,7 @@ extern void(*D3D_clear)(int); extern int(*D3D_canshaders)(void); extern int(*D3D_goodenough)(void); extern bool(*D3D_setcursor)(int, int x, int y, int width, int height, float mx, float my, bool visible, bool noscale); -extern uae_u8* (*D3D_setcursorsurface)(int, int *pitch); +extern uae_u8 *(*D3D_setcursorsurface)(int, int *pitch); extern float(*D3D_getrefreshrate)(int); extern void(*D3D_restore)(int, bool); extern void(*D3D_resize)(int, int); diff --git a/od-win32/direct3d11.cpp b/od-win32/direct3d11.cpp index 4ede0102..e4497722 100644 --- a/od-win32/direct3d11.cpp +++ b/od-win32/direct3d11.cpp @@ -52,7 +52,7 @@ void(*D3D_refresh)(int); bool(*D3D_renderframe)(int, int,bool); void(*D3D_showframe)(int); void(*D3D_showframe_special)(int, int); -uae_u8* (*D3D_locktexture)(int, int*, int*, int); +uae_u8 *(*D3D_locktexture)(int, int*, int*, int*, int); void (*D3D_unlocktexture)(int, int, int); void (*D3D_flushtexture)(int, int miny, int maxy); void (*D3D_guimode)(int, int); @@ -62,7 +62,7 @@ void (*D3D_clear)(int); int (*D3D_canshaders)(void); int (*D3D_goodenough)(void); bool (*D3D_setcursor)(int, int x, int y, int width, int height, float mx, float my, bool visible, bool noscale); -uae_u8* (*D3D_setcursorsurface)(int, int *pitch); +uae_u8 *(*D3D_setcursorsurface)(int, int *pitch); float (*D3D_getrefreshrate)(int); void(*D3D_restore)(int, bool); void(*D3D_resize)(int, int); @@ -4956,7 +4956,7 @@ static bool xD3D11_alloctexture(int monid, int w, int h) return true; } -static uae_u8 *xD3D11_locktexture(int monid, int *pitch, int *height, int fullupdate) +static uae_u8 *xD3D11_locktexture(int monid, int *pitch, int *width, int *height, int fullupdate) { struct d3d11struct *d3d = &d3d11data[monid]; @@ -4975,6 +4975,8 @@ static uae_u8 *xD3D11_locktexture(int monid, int *pitch, int *height, int fullup *pitch = map.RowPitch; if (height) *height = d3d->m_bitmapHeight; + if (width) + *width = d3d->m_bitmapWidth; d3d->texturelocked++; return (uae_u8*)map.pData; } diff --git a/od-win32/gdirender.cpp b/od-win32/gdirender.cpp index 6bc8b116..fb219556 100644 --- a/od-win32/gdirender.cpp +++ b/od-win32/gdirender.cpp @@ -280,13 +280,15 @@ static void gdi_guimode(int monid, int guion) { } -static uae_u8 *gdi_locktexture(int monid, int *pitch, int *height, int fullupdate) +static uae_u8 *gdi_locktexture(int monid, int *pitch, int *width, int *height, int fullupdate) { struct gdistruct *gdi = &gdidata[monid]; if (gdi->bm.bits) { *pitch = gdi->bm.pitch; if (height) *height = gdi->bm.height; + if (width) + *width = gdi->bm.width; return (uae_u8*)gdi->bm.bits; } return NULL; diff --git a/od-win32/picasso96_win.cpp b/od-win32/picasso96_win.cpp index 8ba3430e..b273efb5 100644 --- a/od-win32/picasso96_win.cpp +++ b/od-win32/picasso96_win.cpp @@ -5597,11 +5597,11 @@ static void picasso_flushpixels(int index, uae_u8 *src, int off, bool render) dst = dstp; // safety check - if (pwidth > vidinfo->rowbytes / vidinfo->pixbytes) { - pwidth = vidinfo->rowbytes / vidinfo->pixbytes; + if (pwidth > vidinfo->maxwidth) { + pwidth = vidinfo->maxwidth; } - if (pheight > vidinfo->height) { - pheight = vidinfo->height; + if (pheight > vidinfo->maxheight) { + pheight = vidinfo->maxheight; } if (!split && vidinfo->rtg_clear_flag) { diff --git a/od-win32/picasso96_win.h b/od-win32/picasso96_win.h index d7fd3d19..16852068 100644 --- a/od-win32/picasso96_win.h +++ b/od-win32/picasso96_win.h @@ -667,6 +667,7 @@ extern void picasso_invalidate(int monid, int x, int y, int w, int h); struct picasso_vidbuf_description { int width, height, depth; int rowbytes, pixbytes, offset; + int maxwidth, maxheight; // allocated surface/texture size int extra_mem; /* nonzero if there's a second buffer that must be updated */ uae_u32 rgbformat; uae_u32 selected_rgbformat; diff --git a/od-win32/win32_scaler.cpp b/od-win32/win32_scaler.cpp index f034f139..13b5e306 100644 --- a/od-win32/win32_scaler.cpp +++ b/od-win32/win32_scaler.cpp @@ -1002,7 +1002,7 @@ void S2X_render(int monid, int y_start, int y_end) int aw, ah, aws, ahs; uae_u8 *dptr, *enddptr, *sptr, *endsptr; int ok = 0; - int pitch, surf_height; + int pitch, surf_height, surf_width; uae_u8 *surfstart; aw = amiga_width; @@ -1023,7 +1023,7 @@ void S2X_render(int monid, int y_start, int y_end) if (D3D_restore) D3D_restore(monid, true); - surfstart = D3D_locktexture(monid, &pitch, &surf_height, y_start < -1 ? -1 : (y_start < 0 ? 1 : 0)); + surfstart = D3D_locktexture(monid, &pitch, &surf_width, &surf_height, y_start < -1 ? -1 : (y_start < 0 ? 1 : 0)); if (surfstart == NULL) { return; } diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index 1f816df3..72f083dc 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -1455,7 +1455,7 @@ bool lockscr3d(struct vidbuffer *vb) struct AmigaMonitor *mon = &AMonitors[vb->monitor_id]; if (mon->currentmode.flags & DM_D3D) { if (!(mon->currentmode.flags & DM_SWSCALE)) { - vb->bufmem = D3D_locktexture(vb->monitor_id, &vb->rowbytes, NULL, false); + vb->bufmem = D3D_locktexture(vb->monitor_id, &vb->rowbytes, NULL, NULL, false); if (vb->bufmem) return true; } @@ -1492,7 +1492,7 @@ int lockscr(struct vidbuffer *vb, bool fullupdate, bool first, bool skip) ret = 1; } else { ret = 0; - vb->bufmem = D3D_locktexture(vb->monitor_id, &vb->rowbytes, NULL, skip ? -1 : (fullupdate ? 1 : 0)); + vb->bufmem = D3D_locktexture(vb->monitor_id, &vb->rowbytes, NULL, NULL, skip ? -1 : (fullupdate ? 1 : 0)); if (vb->bufmem) { if (first) init_row_map(); @@ -1661,9 +1661,7 @@ void getrtgfilterrect2(int monid, RECT *sr, RECT *dr, RECT *zr, int *mode, int d static uae_u8 *gfx_lock_picasso2(int monid, bool fullupdate) { struct picasso_vidbuf_description *vidinfo = &picasso_vidinfo[monid]; - int pitch; - uae_u8 *p = D3D_locktexture(monid, &pitch, NULL, fullupdate); - vidinfo->rowbytes = pitch; + uae_u8 *p = D3D_locktexture(monid, &vidinfo->rowbytes, &vidinfo->maxwidth, &vidinfo->maxheight, fullupdate); return p; } uae_u8 *gfx_lock_picasso(int monid, bool fullupdate)