From 6fcdd346a298caab1686bbe8e9ce0bf4a1372731 Mon Sep 17 00:00:00 2001 From: basic2004 Date: Wed, 12 Jul 2017 16:37:13 +0900 Subject: [PATCH 1/2] some Direct3D fixes from mainline Injected some fixes like here. https://bitbucket.org/pcem_emulator/pcem/commits/01425149dc1d5749cd229782fc8e86c41639b50c https://bitbucket.org/pcem_emulator/pcem/commits/666c5c1a50f625021717cc36fc286f57ddee09d8 https://bitbucket.org/pcem_emulator/pcem/commits/84b859b4896ba4f2928a57ab5d6b2189c47217da Locking Windows 10 when fullscreen mode, showing fatal error instead silent crash. --- src/WIN/win_d3d.cc | 27 ++++++++++------- src/WIN/win_d3d_fs.cc | 67 ++++++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/WIN/win_d3d.cc b/src/WIN/win_d3d.cc index 456b67254..dc597fc86 100644 --- a/src/WIN/win_d3d.cc +++ b/src/WIN/win_d3d.cc @@ -95,7 +95,8 @@ int d3d_init(HWND h) d3dpp.BackBufferWidth = 0; d3dpp.BackBufferHeight = 0; - d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, h, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); + if (FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, h, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev))) + fatal("CreateDevice failed\n"); d3d_init_objects(); @@ -125,14 +126,16 @@ void d3d_init_objects() int y; RECT r; - d3ddev->CreateVertexBuffer(12*sizeof(CUSTOMVERTEX), + if (FAILED(d3ddev->CreateVertexBuffer(12*sizeof(CUSTOMVERTEX), 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, D3DPOOL_MANAGED, &v_buffer, - NULL); + NULL))) + fatal("CreateVertexBuffer failed\n"); - d3ddev->CreateTexture(2048, 2048, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &d3dTexture, NULL); + if (FAILED(d3ddev->CreateTexture(2048, 2048, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &d3dTexture, NULL))) + fatal("CreateTexture failed\n"); r.top = r.left = 0; r.bottom = r.right = 2047; @@ -244,19 +247,23 @@ void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) r.bottom = y2; r.right = 2047; + hr = d3dTexture->LockRect(0, &dr, &r, 0); if (hr == D3D_OK) { - if (FAILED(d3dTexture->LockRect(0, &dr, &r, 0))) - fatal("LockRect failed\n"); - for (yy = y1; yy < y2; yy++) - memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(((uint32_t *)buffer32->line[yy + y])[x]), w * 4); + { + if ((y + yy) >= 0 && (y + yy) < buffer32->h) + memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(((uint32_t *)buffer32->line[yy + y])[x]), w * 4); + } video_blit_complete(); d3dTexture->UnlockRect(0); } else + { video_blit_complete(); + return; + } d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0;//0.5 / 2048.0; d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0;//0.5 / 2048.0; @@ -334,11 +341,9 @@ void d3d_blit_memtoscreen_8(int x, int y, int w, int h) r.bottom = h; r.right = 2047; + hr = d3dTexture->LockRect(0, &dr, &r, 0); if (hr == D3D_OK) { - if (FAILED(d3dTexture->LockRect(0, &dr, &r, 0))) - fatal("LockRect failed\n"); - for (yy = 0; yy < h; yy++) { uint32_t *p = (uint32_t *)((uintptr_t)dr.pBits + (yy * dr.Pitch)); diff --git a/src/WIN/win_d3d_fs.cc b/src/WIN/win_d3d_fs.cc index 7a84bc77b..de168cc97 100644 --- a/src/WIN/win_d3d_fs.cc +++ b/src/WIN/win_d3d_fs.cc @@ -213,7 +213,8 @@ int d3d_fs_init(HWND h) d3dpp.BackBufferWidth = d3d_fs_w; d3dpp.BackBufferHeight = d3d_fs_h; - d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, h, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); + if (FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, h, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev))) + fatal("CreateDevice failed\n"); d3d_fs_init_objects(); @@ -243,14 +244,16 @@ static void d3d_fs_init_objects() int y; RECT r; - d3ddev->CreateVertexBuffer(12*sizeof(CUSTOMVERTEX), + if (FAILED(d3ddev->CreateVertexBuffer(12*sizeof(CUSTOMVERTEX), 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, D3DPOOL_MANAGED, &v_buffer, - NULL); + NULL))) + fatal("CreateVertexBuffer failed\n"); - d3ddev->CreateTexture(2048, 2048, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &d3dTexture, NULL); + if (FAILED(d3ddev->CreateTexture(2048, 2048, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &d3dTexture, NULL))) + fatal("CreateTexture failed\n"); r.top = r.left = 0; r.bottom = r.right = 2047; @@ -392,9 +395,9 @@ static void d3d_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) D3DLOCKED_RECT dr; RECT window_rect; int yy; - double l, t, r, b; + double l = 0, t = 0, r = 0, b = 0; - if (y1 == y2) + if (y1 == y2) { video_blit_complete(); return; /*Nothing to do*/ @@ -409,14 +412,20 @@ static void d3d_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) lock_rect.bottom = y2; lock_rect.right = 2047; - if (FAILED(d3dTexture->LockRect(0, &dr, &lock_rect, 0))) - fatal("LockRect failed\n"); - - for (yy = y1; yy < y2; yy++) - memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(((uint32_t *)buffer32->line[yy + y])[x]), w * 4); + hr = d3dTexture->LockRect(0, &dr, &lock_rect, 0); + if (hr == D3D_OK) + { + for (yy = y1; yy < y2; yy++) + memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(((uint32_t *)buffer32->line[yy + y])[x]), w * 4); - video_blit_complete(); - d3dTexture->UnlockRect(0); + video_blit_complete(); + d3dTexture->UnlockRect(0); + } + else + { + video_blit_complete(); + return; + } } else video_blit_complete(); @@ -498,7 +507,7 @@ static void d3d_fs_blit_memtoscreen_8(int x, int y, int w, int h) D3DLOCKED_RECT dr; RECT window_rect; int xx, yy; - double l, t, r, b; + double l = 0, t = 0, r = 0, b = 0; if (!h) { @@ -515,23 +524,27 @@ static void d3d_fs_blit_memtoscreen_8(int x, int y, int w, int h) lock_rect.bottom = 2047; lock_rect.right = 2047; - if (FAILED(d3dTexture->LockRect(0, &dr, &lock_rect, 0))) - fatal("LockRect failed\n"); - - for (yy = 0; yy < h; yy++) + hr = d3dTexture->LockRect(0, &dr, &lock_rect, 0); + if (hr == D3D_OK) { - uint32_t *p = (uint32_t *)((uintptr_t)dr.pBits + (yy * dr.Pitch)); - if ((y + yy) >= 0 && (y + yy) < buffer->h) + for (yy = 0; yy < h; yy++) { - for (xx = 0; xx < w; xx++) - p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; + uint32_t *p = (uint32_t *)((uintptr_t)dr.pBits + (yy * dr.Pitch)); + if ((y + yy) >= 0 && (y + yy) < buffer->h) + { + for (xx = 0; xx < w; xx++) + p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; + } } + video_blit_complete(); + d3dTexture->UnlockRect(0); } - - video_blit_complete(); - - d3dTexture->UnlockRect(0); - } + else + { + video_blit_complete(); + return; + } + } else video_blit_complete(); From 1ffa3275729172fea6719068307c47d52a4fd0cb Mon Sep 17 00:00:00 2001 From: basic2004 Date: Wed, 12 Jul 2017 16:46:51 +0900 Subject: [PATCH 2/2] Fixed change fullscreen with monochrome monitor Fixed 'force changed RGB color monitor' with monochrome monitor mode when changing to fullscreen and leaving, and fixed this problem when changing renderer to Direct3D too. --- src/WIN/win.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/WIN/win.c b/src/WIN/win.c index 15cffbeb6..c843660e5 100644 --- a/src/WIN/win.c +++ b/src/WIN/win.c @@ -1897,6 +1897,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM endblit(); saveconfig(); device_force_redraw(); + cgapal_rebuild(); break; case IDM_VID_FULLSCREEN: @@ -1919,6 +1920,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM endblit(); saveconfig(); device_force_redraw(); + cgapal_rebuild(); } break; @@ -2248,6 +2250,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM mouse_init(); endblit(); device_force_redraw(); + cgapal_rebuild(); break; case WM_KEYDOWN: