From 6274e79beb45724f311c564bca0e709bb6eb350a Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 23 Jan 2024 20:50:25 +0200 Subject: [PATCH] Check texture size also in render backends, if already same, don't reallocate. --- od-win32/direct3d.cpp | 8 +++++++- od-win32/direct3d11.cpp | 32 +++++++++++++++++--------------- od-win32/gdirender.cpp | 5 ++++- od-win32/win32gfx.cpp | 2 +- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/od-win32/direct3d.cpp b/od-win32/direct3d.cpp index a7f2f98c..13d9db9b 100644 --- a/od-win32/direct3d.cpp +++ b/od-win32/direct3d.cpp @@ -202,6 +202,7 @@ struct d3dstruct int ledwidth, ledheight; int max_texture_w, max_texture_h; int tin_w, tin_h, tout_w, tout_h, window_h, window_w; + int tino_w, tino_h; int t_depth, dmult, dmultxh, dmultxv, dmode; int required_sl_texture_w, required_sl_texture_h; int vsync2, guimode, maxscanline, variablerefresh; @@ -3097,9 +3098,14 @@ static bool xD3D_alloctexture (int monid, int w, int h) struct d3dstruct *d3d = &d3ddata[monid]; if (w < 0 || h < 0) { - return d3d->texture1 != NULL; + if (d3d->tino_w == -w && d3d->tino_h == -h && d3d->texture1) { + return true; + } + return false; } + d3d->tino_w = w; + d3d->tino_h = h; d3d->tin_w = w * d3d->dmult; d3d->tin_h = h * d3d->dmult; diff --git a/od-win32/direct3d11.cpp b/od-win32/direct3d11.cpp index add203d1..1c61559a 100644 --- a/od-win32/direct3d11.cpp +++ b/od-win32/direct3d11.cpp @@ -3424,19 +3424,13 @@ static bool xD3D11_initvals(HWND ahwnd, int monid, int w_w, int w_h, int t_w, in if (d3d->m_screenWidth != w_w || d3d->m_screenHeight != w_h) { changed = true; } - if (doalloc && !changed && (d3d->m_bitmapWidth != t_w || d3d->m_bitmapHeight != t_h || d3d->dmultxh != mmulth || d3d->dmultxv != mmultv)) { - d3d->m_bitmapWidth = t_w; - d3d->m_bitmapHeight = t_h; - d3d->dmultxh = mmulth; - d3d->dmultxv = mmultv; - D3D_alloctexture(monid, t_w, t_h); - } - d3d->m_bitmapWidth = t_w; - d3d->m_bitmapHeight = t_h; d3d->m_screenWidth = w_w; d3d->m_screenHeight = w_h; d3d->dmultxh = mmulth; d3d->dmultxv = mmultv; + if (d3d->m_device) { + target_graphics_buffer_update(monid); + } return changed; } @@ -5037,8 +5031,14 @@ static bool xD3D11_alloctexture(int monid, int w, int h) struct d3d11struct *d3d = &d3d11data[monid]; bool v; + if (w == 0 || h == 0) { + return false; + } if (w < 0 || h < 0) { - return d3d->texture2d != NULL; + if (d3d->m_bitmapWidth == -w && d3d->m_bitmapHeight == -h && d3d->texture2d) { + return true; + } + return false; } recheck(d3d, monid); @@ -5336,12 +5336,14 @@ static void updatecursorsurface(int monid) int cy = (int)d3d->cursor_y; int width = sp->width; int height = sp->height; + int bw = d3d->m_bitmapWidth; + int bh = d3d->m_bitmapHeight; if (sp->texture == NULL) { return; } - if (sp->updated && cx >= 0 && cy >= 0 && cx + width <= d3d->m_bitmapWidth && cy + height <= d3d->m_bitmapHeight) { + if (sp->updated && cx >= 0 && cy >= 0 && cx + width <= bw && cy + height <= bh) { return; } @@ -5356,14 +5358,14 @@ static void updatecursorsurface(int monid) for (int h = 0; h < sp->height; h++) { int w = width; int x = 0; - if (cx + w > d3d->m_bitmapWidth) { - w -= (cx + w) - d3d->m_bitmapWidth; + if (cx + w > bw) { + w -= (cx + w) - bw; } if (cx < 0) { x = -cx; w -= -cx; } - if (w <= 0 || cy + h > d3d->m_bitmapHeight) { + if (w <= 0 || cy + h > bh) { memset(b, 0, width * 4); } else { if (x > 0) { @@ -5379,7 +5381,7 @@ static void updatecursorsurface(int monid) } d3d->m_deviceContext->Unmap(d3d->hwsprite.texture, 0); - if (cx >= 0 && cy >= 0 && cx + width <= d3d->m_bitmapWidth && cy + height <= d3d->m_bitmapHeight) { + if (cx >= 0 && cy >= 0 && cx + width <= bw && cy + height <= bh) { sp->updated = true; } } diff --git a/od-win32/gdirender.cpp b/od-win32/gdirender.cpp index 31167cfb..c4452d95 100644 --- a/od-win32/gdirender.cpp +++ b/od-win32/gdirender.cpp @@ -234,7 +234,10 @@ static bool gdi_alloctexture(int monid, int w, int h) struct gdistruct *gdi = &gdidata[monid]; if (w < 0 || h < 0) { - return gdi->hdc != NULL; + if (gdi->bm.width == -w && gdi->bm.height == -h && gdi->hdc) { + return true; + } + return false; } freetexture(monid); diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index 3d3f0bad..6eaa6aeb 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -4161,7 +4161,7 @@ bool target_graphics_buffer_update(int monid) h = vb->outheight; } - if (oldtex_w[monid] == w && oldtex_h[monid] == h && oldtex_rtg[monid] == mon->screen_is_picasso && D3D_alloctexture(mon->monitor_id, -1, -1)) { + if (oldtex_w[monid] == w && oldtex_h[monid] == h && oldtex_rtg[monid] == mon->screen_is_picasso && D3D_alloctexture(mon->monitor_id, -w, -h)) { osk_setup(monid, -2); return false; } -- 2.47.3