Direct3D in full-screen mode now transfers control of input to the full screen window, fixes #429;
Unified screenshot code and moved it to video.c, it is now independent of both renderer and platform; The EGA/(S)VGA overscan now also works for CGA, PCjr, Tandy, and CGA-using Amstrads; Fixed EGA/(S)VGA overscan operation so it works correctly with scrolling and panning; Fixed 320x200x32K and 320x200x64K modes on the ET4000/W32p; Fixed the Video 7 1024i chip ID and video memory options, fixes #431; Fixed a banking bug in the S3 cards, fixes Windows 9x and NeoPaint.
This commit is contained in:
@@ -186,15 +186,6 @@ endif
|
||||
ifndef DINPUT
|
||||
DINPUT := n
|
||||
endif
|
||||
ifndef D3DX
|
||||
D3DX := y
|
||||
ifeq ($(ARM), y)
|
||||
D3DX := n
|
||||
endif
|
||||
ifeq ($(ARM64), y)
|
||||
D3DX := n
|
||||
endif
|
||||
endif
|
||||
ifndef OPENAL
|
||||
OPENAL := y
|
||||
endif
|
||||
@@ -274,7 +265,7 @@ else
|
||||
TOOL_PREFIX := i686-w64-mingw32-
|
||||
endif
|
||||
CPP := ${TOOL_PREFIX}g++
|
||||
CC := ${TOOL_PREFIX}gcc
|
||||
CC := gcc
|
||||
WINDRES := windres
|
||||
STRIP := strip
|
||||
ifeq ($(ARM64), y)
|
||||
@@ -435,10 +426,6 @@ ifeq ($(DINPUT), y)
|
||||
OPTS += -DUSE_DINPUT
|
||||
endif
|
||||
|
||||
ifeq ($(D3DX), y)
|
||||
OPTS += -DUSE_D3DX
|
||||
endif
|
||||
|
||||
# Options for the DEV branch.
|
||||
ifeq ($(DEV_BRANCH), y)
|
||||
OPTS += -DDEV_BRANCH
|
||||
@@ -733,9 +720,6 @@ ifeq ($(DINPUT), y)
|
||||
else
|
||||
LIBS += -lxinput
|
||||
endif
|
||||
ifeq ($(D3DX), y)
|
||||
LIBS += -ld3dx9
|
||||
endif
|
||||
|
||||
ifeq ($(STATIC), y)
|
||||
LIBS += -static
|
||||
|
||||
@@ -186,15 +186,6 @@ endif
|
||||
ifndef DINPUT
|
||||
DINPUT := n
|
||||
endif
|
||||
ifndef D3DX
|
||||
D3DX := y
|
||||
ifeq ($(ARM), y)
|
||||
D3DX := n
|
||||
endif
|
||||
ifeq ($(ARM64), y)
|
||||
D3DX := n
|
||||
endif
|
||||
endif
|
||||
ifndef OPENAL
|
||||
OPENAL := y
|
||||
endif
|
||||
@@ -441,10 +432,6 @@ ifeq ($(DINPUT), y)
|
||||
OPTS += -DUSE_DINPUT
|
||||
endif
|
||||
|
||||
ifeq ($(D3DX), y)
|
||||
OPTS += -DUSE_D3DX
|
||||
endif
|
||||
|
||||
# Options for the DEV branch.
|
||||
ifeq ($(DEV_BRANCH), y)
|
||||
OPTS += -DDEV_BRANCH
|
||||
@@ -739,9 +726,6 @@ ifeq ($(DINPUT), y)
|
||||
else
|
||||
LIBS += -lxinput
|
||||
endif
|
||||
ifeq ($(D3DX), y)
|
||||
LIBS += -ld3dx9
|
||||
endif
|
||||
|
||||
ifeq ($(STATIC), y)
|
||||
LIBS += -static
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Platform main support module for Windows.
|
||||
*
|
||||
* Version: @(#)win.c 1.0.57 2019/03/06
|
||||
* Version: @(#)win.c 1.0.58 2019/10/19
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "../86box.h"
|
||||
#include "../config.h"
|
||||
#include "../device.h"
|
||||
#include "../keyboard.h"
|
||||
#include "../mouse.h"
|
||||
#include "../video/video.h"
|
||||
#define GLOBAL
|
||||
@@ -84,28 +85,27 @@ static const struct {
|
||||
void (*resize)(int x, int y);
|
||||
int (*pause)(void);
|
||||
void (*enable)(int enable);
|
||||
void (*screenshot)(const wchar_t *fn);
|
||||
} vid_apis[2][RENDERERS_NUM] = {
|
||||
{
|
||||
{ "DDraw", 1, (int(*)(void*))ddraw_init, ddraw_close, NULL, ddraw_pause, ddraw_enable, ddraw_take_screenshot },
|
||||
{ "DDraw", 1, (int(*)(void*))ddraw_init, ddraw_close, NULL, ddraw_pause, ddraw_enable },
|
||||
#ifdef USE_D2D
|
||||
{ "D2D", 1, (int(*)(void*))d2d_init, d2d_close, NULL, d2d_pause, d2d_enable, d2d_take_screenshot },
|
||||
{ "D2D", 1, (int(*)(void*))d2d_init, d2d_close, NULL, d2d_pause, d2d_enable },
|
||||
#endif
|
||||
{ "D3D", 1, (int(*)(void*))d3d_init, d3d_close, d3d_resize, d3d_pause, d3d_enable, d3d_take_screenshot },
|
||||
{ "SDL", 1, (int(*)(void*))sdl_init, sdl_close, NULL, sdl_pause, sdl_enable, sdl_take_screenshot }
|
||||
{ "D3D", 1, (int(*)(void*))d3d_init, d3d_close, d3d_resize, d3d_pause, d3d_enable },
|
||||
{ "SDL", 1, (int(*)(void*))sdl_init, sdl_close, NULL, sdl_pause, sdl_enable }
|
||||
#ifdef USE_VNC
|
||||
,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL, vnc_take_screenshot }
|
||||
,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL }
|
||||
#endif
|
||||
},
|
||||
{
|
||||
{ "DDraw", 1, (int(*)(void*))ddraw_init_fs, ddraw_close, NULL, ddraw_pause, ddraw_enable, ddraw_take_screenshot },
|
||||
{ "DDraw", 1, (int(*)(void*))ddraw_init_fs, ddraw_close, NULL, ddraw_pause, ddraw_enable },
|
||||
#ifdef USE_D2D
|
||||
{ "D2D", 1, (int(*)(void*))d2d_init_fs, d2d_close, NULL, d2d_pause, d2d_enable, d2d_take_screenshot },
|
||||
{ "D2D", 1, (int(*)(void*))d2d_init_fs, d2d_close, NULL, d2d_pause, d2d_enable },
|
||||
#endif
|
||||
{ "D3D", 1, (int(*)(void*))d3d_init_fs, d3d_close, NULL, d3d_pause, d3d_enable, d3d_take_screenshot },
|
||||
{ "SDL", 1, (int(*)(void*))sdl_init_fs, sdl_close, sdl_resize, sdl_pause, sdl_enable, sdl_take_screenshot }
|
||||
{ "D3D", 1, (int(*)(void*))d3d_init_fs, d3d_close, NULL, d3d_pause, d3d_enable },
|
||||
{ "SDL", 1, (int(*)(void*))sdl_init_fs, sdl_close, sdl_resize, sdl_pause, sdl_enable }
|
||||
#ifdef USE_VNC
|
||||
,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL, vnc_take_screenshot }
|
||||
,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL }
|
||||
#endif
|
||||
},
|
||||
};
|
||||
@@ -815,6 +815,8 @@ plat_setfullscreen(int on)
|
||||
startblit();
|
||||
video_wait_for_blit();
|
||||
|
||||
plat_vidapi_enable(0);
|
||||
|
||||
win_mouse_close();
|
||||
|
||||
/* Close the current mode, and open the new one. */
|
||||
@@ -825,10 +827,15 @@ plat_setfullscreen(int on)
|
||||
|
||||
win_mouse_init();
|
||||
|
||||
plat_vidapi_enable(1);
|
||||
|
||||
/* Release video and make it redraw the screen. */
|
||||
endblit();
|
||||
device_force_redraw();
|
||||
|
||||
/* Send a CTRL break code so CTRL does not get stuck. */
|
||||
keyboard_input(0, 0x01D);
|
||||
|
||||
/* Finally, handle the host's mouse cursor. */
|
||||
/* win_log("%s full screen, %s cursor\n", on ? "enter" : "leave", on ? "hide" : "show"); */
|
||||
show_cursor(video_fullscreen ? 0 : -1);
|
||||
@@ -838,30 +845,10 @@ plat_setfullscreen(int on)
|
||||
void
|
||||
take_screenshot(void)
|
||||
{
|
||||
wchar_t path[1024], fn[128];
|
||||
struct tm *info;
|
||||
time_t now;
|
||||
|
||||
if (!vid_api_inited || !vid_apis[video_fullscreen][vid_api].screenshot) return;
|
||||
win_log("Screenshot: video API is: %i\n", vid_api);
|
||||
if ((vid_api < 0) || (vid_api >= RENDERERS_NUM)) return;
|
||||
|
||||
memset(fn, 0, sizeof(fn));
|
||||
memset(path, 0, sizeof(path));
|
||||
|
||||
(void)time(&now);
|
||||
info = localtime(&now);
|
||||
|
||||
plat_append_filename(path, usr_path, SCREENSHOT_PATH);
|
||||
|
||||
if (! plat_dir_check(path))
|
||||
plat_dir_create(path);
|
||||
|
||||
wcscat(path, L"\\");
|
||||
|
||||
wcsftime(fn, 128, L"%Y%m%d_%H%M%S.png", info);
|
||||
wcscat(path, fn);
|
||||
vid_apis[video_fullscreen][vid_api].screenshot((const wchar_t *) path);
|
||||
startblit();
|
||||
screenshots++;
|
||||
endblit();
|
||||
device_force_redraw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Rendering module for Microsoft Direct2D.
|
||||
*
|
||||
* Version: @(#)win_d2d.cpp 1.0.3 2019/03/09
|
||||
* Version: @(#)win_d2d.cpp 1.0.4 2019/10/12
|
||||
*
|
||||
* Authors: David Hrdlička, <hrdlickadavid@outlook.com>
|
||||
*
|
||||
@@ -505,18 +505,6 @@ d2d_pause(void)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
d2d_take_screenshot(const wchar_t *fn)
|
||||
{
|
||||
// Saving a screenshot of a Direct2D render target is harder than
|
||||
// one would think. Keeping this stubbed for the moment
|
||||
// -ryu
|
||||
|
||||
d2d_log("Direct2D: d2d_take_screenshot(%s)\n", fn);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
d2d_enable(int enable)
|
||||
{
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
*
|
||||
* Definitions for the Direct2D rendering module.
|
||||
*
|
||||
* Version: @(#)win_d2d.h 1.0.0 2018/07/19
|
||||
* Version: @(#)win_d2d.h 1.0.1 2019/10/12
|
||||
*
|
||||
* Authors: David Hrdlička, <hrdlickadavid@outlook.com>
|
||||
*
|
||||
* Copyright 2018 David Hrdlička.
|
||||
* Copyright 2018,2019 David Hrdlička.
|
||||
*/
|
||||
#ifndef WIN_D2D_H
|
||||
# define WIN_D2D_H
|
||||
@@ -25,7 +25,6 @@ extern void d2d_close(void);
|
||||
extern int d2d_init(HWND h);
|
||||
extern int d2d_init_fs(HWND h);
|
||||
extern int d2d_pause(void);
|
||||
extern void d2d_take_screenshot(const wchar_t *fn);
|
||||
extern void d2d_enable(int enable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Rendering module for Microsoft Direct3D 9.
|
||||
*
|
||||
* Version: @(#)win_d3d.cpp 1.0.12 2019/03/09
|
||||
* Version: @(#)win_d3d.cpp 1.0.13 2019/10/12
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -145,6 +145,7 @@ d3d_size(RECT w_rect, double *l, double *t, double *r, double *b, int w, int h)
|
||||
static void
|
||||
d3d_blit_fs(int x, int y, int y1, int y2, int w, int h)
|
||||
{
|
||||
#if 0
|
||||
HRESULT hr = D3D_OK;
|
||||
HRESULT hbsr = D3D_OK;
|
||||
VOID* pVoid;
|
||||
@@ -152,6 +153,7 @@ d3d_blit_fs(int x, int y, int y1, int y2, int w, int h)
|
||||
RECT w_rect;
|
||||
int yy;
|
||||
double l = 0, t = 0, r = 0, b = 0;
|
||||
RECT lock_rect;
|
||||
|
||||
if (!d3d_enabled) {
|
||||
video_blit_complete();
|
||||
@@ -163,33 +165,28 @@ d3d_blit_fs(int x, int y, int y1, int y2, int w, int h)
|
||||
return; /*Nothing to do*/
|
||||
}
|
||||
|
||||
if (hr == D3D_OK && !(y1 == 0 && y2 == 0)) {
|
||||
RECT lock_rect;
|
||||
lock_rect.top = y1;
|
||||
lock_rect.left = 0;
|
||||
lock_rect.bottom = y2;
|
||||
lock_rect.right = 2047;
|
||||
|
||||
lock_rect.top = y1;
|
||||
lock_rect.left = 0;
|
||||
lock_rect.bottom = y2;
|
||||
lock_rect.right = 2047;
|
||||
|
||||
hr = d3dTexture->LockRect(0, &dr, &lock_rect, 0);
|
||||
if (hr == D3D_OK) {
|
||||
for (yy = y1; yy < y2; yy++) {
|
||||
if (buffer32) {
|
||||
if (video_grayscale || invert_display)
|
||||
video_transform_copy((uint32_t *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(buffer32->line[yy + y][x]), w);
|
||||
else
|
||||
memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(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++) {
|
||||
if (buffer32) {
|
||||
if (video_grayscale || invert_display)
|
||||
video_transform_copy((uint32_t *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(buffer32->line[yy + y][x]), w);
|
||||
else
|
||||
memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(buffer32->line[yy + y][x]), w * 4);
|
||||
}
|
||||
|
||||
video_blit_complete();
|
||||
d3dTexture->UnlockRect(0);
|
||||
} else {
|
||||
video_blit_complete();
|
||||
return;
|
||||
}
|
||||
} else
|
||||
|
||||
video_blit_complete();
|
||||
d3dTexture->UnlockRect(0);
|
||||
} else {
|
||||
video_blit_complete();
|
||||
return;
|
||||
}
|
||||
|
||||
d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0;
|
||||
d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0;
|
||||
@@ -258,6 +255,115 @@ d3d_blit_fs(int x, int y, int y1, int y2, int w, int h)
|
||||
|
||||
if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL)
|
||||
PostMessage(hwndMain, WM_RESETD3D, 0, 0);
|
||||
#else
|
||||
HRESULT hr = D3D_OK;
|
||||
HRESULT hbsr = D3D_OK;
|
||||
VOID* pVoid;
|
||||
D3DLOCKED_RECT dr;
|
||||
RECT r, w_rect;
|
||||
int yy;
|
||||
double l = 0, t = 0, rr = 0, b = 0;
|
||||
|
||||
if (!d3d_enabled) {
|
||||
video_blit_complete();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((y1 == y2) || (h <= 0)) {
|
||||
video_blit_complete();
|
||||
return; /*Nothing to do*/
|
||||
}
|
||||
|
||||
r.top = y1;
|
||||
r.left = 0;
|
||||
r.bottom = y2;
|
||||
r.right = 2047;
|
||||
|
||||
hr = d3dTexture->LockRect(0, &dr, &r, 0);
|
||||
if (hr == D3D_OK) {
|
||||
for (yy = y1; yy < y2; yy++) {
|
||||
if (buffer32) {
|
||||
if ((y + yy) >= 0 && (y + yy) < buffer32->h) {
|
||||
if (video_grayscale || invert_display)
|
||||
video_transform_copy((uint32_t *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(buffer32->line[yy + y][x]), w);
|
||||
else
|
||||
memcpy((void *)((uintptr_t)dr.pBits + ((yy - y1) * dr.Pitch)), &(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;
|
||||
d3d_verts[1].tu = d3d_verts[4].tu = d3d_verts[5].tu = (float)w / 2048.0;
|
||||
d3d_verts[1].tv = d3d_verts[2].tv = d3d_verts[5].tv = (float)h / 2048.0;
|
||||
d3d_verts[0].color = d3d_verts[1].color = d3d_verts[2].color =
|
||||
d3d_verts[3].color = d3d_verts[4].color = d3d_verts[5].color =
|
||||
d3d_verts[6].color = d3d_verts[7].color = d3d_verts[8].color =
|
||||
d3d_verts[9].color = d3d_verts[10].color = d3d_verts[11].color = 0xffffff;
|
||||
|
||||
GetClientRect(d3d_device_window, &w_rect);
|
||||
d3d_size(w_rect, &l, &t, &rr, &b, w, h);
|
||||
|
||||
d3d_verts[0].x = l;
|
||||
d3d_verts[0].y = t;
|
||||
d3d_verts[1].x = rr;
|
||||
d3d_verts[1].y = b;
|
||||
d3d_verts[2].x = l;
|
||||
d3d_verts[2].y = b;
|
||||
d3d_verts[3].x = l;
|
||||
d3d_verts[3].y = t;
|
||||
d3d_verts[4].x = rr;
|
||||
d3d_verts[4].y = t;
|
||||
d3d_verts[5].x = rr;
|
||||
d3d_verts[5].y = b;
|
||||
d3d_verts[6].x = d3d_verts[8].x = d3d_verts[9].x = rr - 40.5;
|
||||
d3d_verts[6].y = d3d_verts[9].y = d3d_verts[10].y = t + 8.5;
|
||||
d3d_verts[7].x = d3d_verts[10].x = d3d_verts[11].x = rr - 8.5;
|
||||
d3d_verts[7].y = d3d_verts[8].y = d3d_verts[11].y = t + 14.5;
|
||||
|
||||
if (hr == D3D_OK)
|
||||
hr = v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer
|
||||
if (hr == D3D_OK)
|
||||
memcpy(pVoid, d3d_verts, sizeof(d3d_verts)); // copy the vertices to the locked buffer
|
||||
if (hr == D3D_OK)
|
||||
hr = v_buffer->Unlock(); // unlock the vertex buffer
|
||||
|
||||
if (hr == D3D_OK)
|
||||
hbsr = hr = d3ddev->BeginScene();
|
||||
|
||||
if (hr == D3D_OK) {
|
||||
if (hr == D3D_OK)
|
||||
hr = d3ddev->SetTexture(0, d3dTexture);
|
||||
|
||||
if (hr == D3D_OK)
|
||||
hr = d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
|
||||
|
||||
if (hr == D3D_OK)
|
||||
hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
|
||||
|
||||
if (hr == D3D_OK)
|
||||
hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
|
||||
|
||||
if (hr == D3D_OK)
|
||||
hr = d3ddev->SetTexture(0, NULL);
|
||||
}
|
||||
|
||||
if (hbsr == D3D_OK)
|
||||
hr = d3ddev->EndScene();
|
||||
|
||||
if (hr == D3D_OK)
|
||||
hr = d3ddev->Present(NULL, NULL, d3d_device_window, NULL);
|
||||
|
||||
if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL)
|
||||
PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -404,9 +510,14 @@ d3d_init_objects(void)
|
||||
}
|
||||
|
||||
|
||||
static int old_capture = 0;
|
||||
|
||||
|
||||
int
|
||||
d3d_init(HWND h)
|
||||
{
|
||||
RECT rect;
|
||||
|
||||
d3d_hwnd = h;
|
||||
|
||||
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
@@ -434,6 +545,16 @@ d3d_init(HWND h)
|
||||
|
||||
d3d_init_objects();
|
||||
|
||||
mouse_capture = old_capture;
|
||||
|
||||
if (mouse_capture) {
|
||||
GetWindowRect(hwndRender, &rect);
|
||||
|
||||
ClipCursor(&rect);
|
||||
}
|
||||
|
||||
d3d_device_window = NULL;
|
||||
|
||||
video_setblit(d3d_blit);
|
||||
|
||||
d3d_enabled = 1;
|
||||
@@ -446,6 +567,7 @@ int
|
||||
d3d_init_fs(HWND h)
|
||||
{
|
||||
WCHAR title[200];
|
||||
RECT rect;
|
||||
|
||||
d3d_w = GetSystemMetrics(SM_CXSCREEN);
|
||||
d3d_h = GetSystemMetrics(SM_CYSCREEN);
|
||||
@@ -491,9 +613,22 @@ d3d_init_fs(HWND h)
|
||||
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
|
||||
&d3dpp, &d3ddev)))
|
||||
fatal("CreateDevice failed\n");
|
||||
|
||||
|
||||
d3d_init_objects();
|
||||
|
||||
/* Redirect RawInput to this new window. */
|
||||
plat_set_input(d3d_device_window);
|
||||
|
||||
SetFocus(d3d_device_window);
|
||||
|
||||
old_capture = mouse_capture;
|
||||
|
||||
GetWindowRect(d3d_device_window, &rect);
|
||||
|
||||
ClipCursor(&rect);
|
||||
|
||||
mouse_capture = 1;
|
||||
|
||||
video_setblit(d3d_blit_fs);
|
||||
|
||||
d3d_enabled = 1;
|
||||
@@ -518,7 +653,7 @@ d3d_close_objects(void)
|
||||
|
||||
void
|
||||
d3d_close(void)
|
||||
{
|
||||
{
|
||||
video_setblit(NULL);
|
||||
|
||||
if (d3d_enabled)
|
||||
@@ -536,6 +671,12 @@ d3d_close(void)
|
||||
}
|
||||
|
||||
if (d3d_device_window != NULL) {
|
||||
plat_set_input(hwndMain);
|
||||
|
||||
ShowWindow(hwndRender, TRUE);
|
||||
|
||||
SetFocus(hwndMain);
|
||||
|
||||
DestroyWindow(d3d_device_window);
|
||||
d3d_device_window = NULL;
|
||||
}
|
||||
@@ -631,164 +772,6 @@ d3d_pause(void)
|
||||
}
|
||||
|
||||
|
||||
#ifndef USE_D3DX
|
||||
static void
|
||||
SavePNG(wchar_t *szFilename, D3DSURFACE_DESC *surfaceDesc, D3DLOCKED_RECT *d3dlr)
|
||||
{
|
||||
BITMAPINFO bmpInfo;
|
||||
HDC hdc;
|
||||
LPVOID pBuf = NULL;
|
||||
LPVOID pBuf2 = NULL;
|
||||
png_bytep *b_rgb = NULL;
|
||||
int i;
|
||||
|
||||
/* create file */
|
||||
FILE *fp = plat_fopen(szFilename, (wchar_t *) L"wb");
|
||||
if (!fp) {
|
||||
ddraw_log("[SavePNG] File %ls could not be opened for writing", szFilename);
|
||||
return;
|
||||
}
|
||||
|
||||
/* initialize stuff */
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
|
||||
if (!png_ptr) {
|
||||
ddraw_log("[SavePNG] png_create_write_struct failed");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
ddraw_log("[SavePNG] png_create_info_struct failed");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
hdc = GetDC(NULL);
|
||||
|
||||
ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
|
||||
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
|
||||
GetDIBits(hdc, hBitmap, 0, 0, NULL, &bmpInfo, DIB_RGB_COLORS);
|
||||
|
||||
if (bmpInfo.bmiHeader.biSizeImage <= 0)
|
||||
bmpInfo.bmiHeader.biSizeImage =
|
||||
bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
|
||||
|
||||
pBuf = malloc(bmpInfo.bmiHeader.biSizeImage);
|
||||
if (pBuf == NULL) {
|
||||
ddraw_log("[SavePNG] Unable to Allocate Bitmap Memory");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ys2 <= 250) {
|
||||
pBuf2 = malloc(bmpInfo.bmiHeader.biSizeImage << 1);
|
||||
if (pBuf2 == NULL) {
|
||||
ddraw_log("[SavePNG] Unable to Allocate Secondary Bitmap Memory");
|
||||
free(pBuf);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ddraw_log("save png w=%i h=%i\n", bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight);
|
||||
|
||||
bmpInfo.bmiHeader.biCompression = BI_RGB;
|
||||
|
||||
GetDIBits(hdc, hBitmap, 0, bmpInfo.bmiHeader.biHeight, pBuf, &bmpInfo, DIB_RGB_COLORS);
|
||||
|
||||
if (pBuf2) {
|
||||
bmpInfo.bmiHeader.biSizeImage <<= 1;
|
||||
bmpInfo.bmiHeader.biHeight <<= 1;
|
||||
}
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight,
|
||||
8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
b_rgb = (png_bytep *) malloc(sizeof(png_bytep) * bmpInfo.bmiHeader.biHeight);
|
||||
if (b_rgb == NULL) {
|
||||
ddraw_log("[SavePNG] Unable to Allocate RGB Bitmap Memory");
|
||||
free(pBuf2);
|
||||
free(pBuf);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < bmpInfo.bmiHeader.biHeight; i++) {
|
||||
b_rgb[i] = (png_byte *) malloc(png_get_rowbytes(png_ptr, info_ptr));
|
||||
}
|
||||
|
||||
if (pBuf2) {
|
||||
DoubleLines((uint8_t *) pBuf2, (uint8_t *) pBuf);
|
||||
bgra_to_rgb(b_rgb, (uint8_t *) pBuf2, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight);
|
||||
} else
|
||||
bgra_to_rgb(b_rgb, (uint8_t *) pBuf, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight);
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
png_write_image(png_ptr, b_rgb);
|
||||
|
||||
png_write_end(png_ptr, NULL);
|
||||
|
||||
/* cleanup heap allocation */
|
||||
if (hdc) ReleaseDC(NULL,hdc);
|
||||
|
||||
for (i = 0; i < bmpInfo.bmiHeader.biHeight; i++)
|
||||
if (b_rgb[i]) free(b_rgb[i]);
|
||||
|
||||
if (b_rgb) free(b_rgb);
|
||||
|
||||
if (pBuf2) free(pBuf2);
|
||||
|
||||
if (pBuf) free(pBuf);
|
||||
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
d3d_take_screenshot(const wchar_t *fn)
|
||||
{
|
||||
#ifdef USE_D3DX
|
||||
LPDIRECT3DSURFACE9 d3dSurface = NULL;
|
||||
|
||||
if (! d3dTexture) return;
|
||||
|
||||
d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &d3dSurface);
|
||||
D3DXSaveSurfaceToFile(fn, D3DXIFF_PNG, d3dSurface, NULL, NULL);
|
||||
|
||||
d3dSurface->Release();
|
||||
d3dSurface = NULL;
|
||||
#else
|
||||
/* TODO: how to take screenshot without d3dx?
|
||||
just a stub for now */
|
||||
LPDIRECT3DSURFACE9 d3dSurface = NULL;
|
||||
D3DSURFACE_DESC surfaceDesc;
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
BYTE *pSurfaceBuffer;
|
||||
|
||||
if (! d3dTexture) return;
|
||||
|
||||
d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &d3dSurface);
|
||||
d3dSurface->GetDesc(&surfaceDesc);
|
||||
d3dSurface->LockRect(&d3dlr, 0, D3DLOCK_DONOTWAIT);
|
||||
pSurfaceBuffer = (BYTE *) d3dlr.pBits + d3dlr.Pitch * (surfaceDesc.Height - 1);
|
||||
|
||||
D3DXSaveSurfaceToFile(fn, D3DXIFF_PNG, d3dSurface, NULL, NULL);
|
||||
|
||||
d3dSurface->Release();
|
||||
d3dSurface = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
d3d_enable(int enable)
|
||||
{
|
||||
|
||||
@@ -8,20 +8,19 @@
|
||||
*
|
||||
* Direct3D 9 rendererer and screenshots taking.
|
||||
*
|
||||
* Version: @(#)win_d3d.h 1.0.3 2017/11/12
|
||||
* Version: @(#)win_d3d.h 1.0.4 2019/10/12
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
*
|
||||
* Copyright 2008-2017 Sarah Walker.
|
||||
* Copyright 2016,2017 Miran Grca.
|
||||
* Copyright 2008-2019 Sarah Walker.
|
||||
* Copyright 2016-2019 Miran Grca.
|
||||
*/
|
||||
#ifndef WIN_D3D_H
|
||||
# define WIN_D3D_H
|
||||
# define UNICODE
|
||||
# define BITMAP WINDOWS_BITMAP
|
||||
# include <d3d9.h>
|
||||
# include <d3dx9tex.h>
|
||||
# undef BITMAP
|
||||
|
||||
|
||||
@@ -36,7 +35,6 @@ extern void d3d_reset(void);
|
||||
extern void d3d_reset_fs(void);
|
||||
extern int d3d_pause(void);
|
||||
extern void d3d_resize(int x, int y);
|
||||
extern void d3d_take_screenshot(const wchar_t *fn);
|
||||
extern void d3d_enable(int enable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* NOTES: This code should be re-merged into a single init() with a
|
||||
* 'fullscreen' argument, indicating FS mode is requested.
|
||||
*
|
||||
* Version: @(#)win_ddraw.cpp 1.0.14 2019/03/09
|
||||
* Version: @(#)win_ddraw.cpp 1.0.15 2019/10/12
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -29,9 +29,6 @@
|
||||
#include <windows.h>
|
||||
#undef BITMAP
|
||||
|
||||
#define PNG_DEBUG 0
|
||||
#include <png.h>
|
||||
|
||||
#define HAVE_STDARG_H
|
||||
#include "../86box.h"
|
||||
#include "../device.h"
|
||||
@@ -50,14 +47,9 @@ static LPDIRECTDRAWSURFACE4 lpdds_pri = NULL,
|
||||
static LPDIRECTDRAWCLIPPER lpdd_clipper = NULL;
|
||||
static DDSURFACEDESC2 ddsd;
|
||||
static HWND ddraw_hwnd;
|
||||
static HBITMAP hbitmap;
|
||||
static int ddraw_w, ddraw_h,
|
||||
xs, ys, ys2;
|
||||
static int ddraw_w, ddraw_h;
|
||||
static volatile int ddraw_enabled = 0;
|
||||
|
||||
static png_structp png_ptr;
|
||||
static png_infop info_ptr;
|
||||
|
||||
|
||||
#ifdef ENABLE_DDRAW_LOG
|
||||
int ddraw_do_log = ENABLE_DDRAW_LOG;
|
||||
@@ -79,180 +71,6 @@ ddraw_log(const char *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
CopySurface(IDirectDrawSurface4 *pDDSurface)
|
||||
{
|
||||
HDC hdc, hmemdc;
|
||||
HBITMAP hprevbitmap;
|
||||
DDSURFACEDESC2 ddsd2;
|
||||
|
||||
pDDSurface->GetDC(&hdc);
|
||||
hmemdc = CreateCompatibleDC(hdc);
|
||||
ZeroMemory(&ddsd2 ,sizeof( ddsd2 )); // better to clear before using
|
||||
ddsd2.dwSize = sizeof( ddsd2 ); //initialize with size
|
||||
pDDSurface->GetSurfaceDesc(&ddsd2);
|
||||
hbitmap = CreateCompatibleBitmap( hdc ,xs ,ys);
|
||||
hprevbitmap = (HBITMAP) SelectObject( hmemdc, hbitmap );
|
||||
BitBlt(hmemdc,0 ,0 ,xs ,ys ,hdc ,0 ,0,SRCCOPY);
|
||||
SelectObject(hmemdc,hprevbitmap); // restore the old bitmap
|
||||
DeleteDC(hmemdc);
|
||||
pDDSurface->ReleaseDC(hdc);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
bgra_to_rgb(png_bytep *b_rgb, uint8_t *bgra, int width, int height)
|
||||
{
|
||||
int i, j;
|
||||
uint8_t *r, *b;
|
||||
|
||||
if (video_grayscale || invert_display)
|
||||
*bgra = video_color_transform(*bgra);
|
||||
|
||||
for (i = 0; i < height; i++) {
|
||||
for (j = 0; j < width; j++) {
|
||||
r = &b_rgb[(height - 1) - i][j * 3];
|
||||
b = &bgra[((i * width) + j) * 4];
|
||||
r[0] = b[2];
|
||||
r[1] = b[1];
|
||||
r[2] = b[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
DoubleLines(uint8_t *dst, uint8_t *src)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < ys; i++) {
|
||||
memcpy(dst + (i * xs * 8), src + (i * xs * 4), xs * 4);
|
||||
memcpy(dst + ((i * xs * 8) + (xs * 4)), src + (i * xs * 4), xs * 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
SavePNG(const wchar_t *szFilename, HBITMAP hBitmap)
|
||||
{
|
||||
BITMAPINFO bmpInfo;
|
||||
HDC hdc;
|
||||
LPVOID pBuf = NULL;
|
||||
LPVOID pBuf2 = NULL;
|
||||
png_bytep *b_rgb = NULL;
|
||||
int i;
|
||||
|
||||
/* create file */
|
||||
FILE *fp = plat_fopen((wchar_t *) szFilename, (wchar_t *) L"wb");
|
||||
if (!fp) {
|
||||
ddraw_log("[SavePNG] File %ls could not be opened for writing", szFilename);
|
||||
return;
|
||||
}
|
||||
|
||||
/* initialize stuff */
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
|
||||
if (!png_ptr) {
|
||||
ddraw_log("[SavePNG] png_create_write_struct failed");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
ddraw_log("[SavePNG] png_create_info_struct failed");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
hdc = GetDC(NULL);
|
||||
|
||||
ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
|
||||
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
|
||||
GetDIBits(hdc, hBitmap, 0, 0, NULL, &bmpInfo, DIB_RGB_COLORS);
|
||||
|
||||
if (bmpInfo.bmiHeader.biSizeImage <= 0)
|
||||
bmpInfo.bmiHeader.biSizeImage =
|
||||
bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
|
||||
|
||||
pBuf = malloc(bmpInfo.bmiHeader.biSizeImage);
|
||||
if (pBuf == NULL) {
|
||||
ddraw_log("[SavePNG] Unable to Allocate Bitmap Memory");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ys2 <= 250) {
|
||||
pBuf2 = malloc(bmpInfo.bmiHeader.biSizeImage << 1);
|
||||
if (pBuf2 == NULL) {
|
||||
ddraw_log("[SavePNG] Unable to Allocate Secondary Bitmap Memory");
|
||||
free(pBuf);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ddraw_log("save png w=%i h=%i\n", bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight);
|
||||
|
||||
bmpInfo.bmiHeader.biCompression = BI_RGB;
|
||||
|
||||
GetDIBits(hdc, hBitmap, 0, bmpInfo.bmiHeader.biHeight, pBuf, &bmpInfo, DIB_RGB_COLORS);
|
||||
|
||||
if (pBuf2) {
|
||||
bmpInfo.bmiHeader.biSizeImage <<= 1;
|
||||
bmpInfo.bmiHeader.biHeight <<= 1;
|
||||
}
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight,
|
||||
8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
b_rgb = (png_bytep *) malloc(sizeof(png_bytep) * bmpInfo.bmiHeader.biHeight);
|
||||
if (b_rgb == NULL) {
|
||||
ddraw_log("[SavePNG] Unable to Allocate RGB Bitmap Memory");
|
||||
free(pBuf2);
|
||||
free(pBuf);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < bmpInfo.bmiHeader.biHeight; i++) {
|
||||
b_rgb[i] = (png_byte *) malloc(png_get_rowbytes(png_ptr, info_ptr));
|
||||
}
|
||||
|
||||
if (pBuf2) {
|
||||
DoubleLines((uint8_t *) pBuf2, (uint8_t *) pBuf);
|
||||
bgra_to_rgb(b_rgb, (uint8_t *) pBuf2, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight);
|
||||
} else
|
||||
bgra_to_rgb(b_rgb, (uint8_t *) pBuf, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight);
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
png_write_image(png_ptr, b_rgb);
|
||||
|
||||
png_write_end(png_ptr, NULL);
|
||||
|
||||
/* cleanup heap allocation */
|
||||
if (hdc) ReleaseDC(NULL,hdc);
|
||||
|
||||
for (i = 0; i < bmpInfo.bmiHeader.biHeight; i++)
|
||||
if (b_rgb[i]) free(b_rgb[i]);
|
||||
|
||||
if (b_rgb) free(b_rgb);
|
||||
|
||||
if (pBuf2) free(pBuf2);
|
||||
|
||||
if (pBuf) free(pBuf);
|
||||
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ddraw_fs_size_default(RECT w_rect, RECT *r_dest)
|
||||
{
|
||||
@@ -495,42 +313,6 @@ ddraw_blit(int x, int y, int y1, int y2, int w, int h)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ddraw_take_screenshot(const wchar_t *fn)
|
||||
{
|
||||
#if 0
|
||||
xs = xsize;
|
||||
ys = ys2 = ysize;
|
||||
|
||||
/* For EGA/(S)VGA, the size is NOT adjusted for overscan. */
|
||||
if ((overscan_y > 16) && enable_overscan) {
|
||||
xs += overscan_x;
|
||||
ys += overscan_y;
|
||||
}
|
||||
|
||||
/* For CGA, the width is adjusted for overscan, but the height is not. */
|
||||
if (overscan_y == 16) {
|
||||
if (ys2 <= 250)
|
||||
ys += (overscan_y >> 1);
|
||||
else
|
||||
ys += overscan_y;
|
||||
}
|
||||
#endif
|
||||
|
||||
xs = get_actual_size_x();
|
||||
ys = ys2 = get_actual_size_y();
|
||||
|
||||
if (ysize <= 250) {
|
||||
ys >>= 1;
|
||||
ys2 >>= 1;
|
||||
}
|
||||
|
||||
CopySurface(lpdds_back2);
|
||||
|
||||
SavePNG(fn, hbitmap);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ddraw_init(HWND h)
|
||||
{
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
*
|
||||
* Definitions for the DirectDraw 9 rendering module.
|
||||
*
|
||||
* Version: @(#)win_ddraw.h 1.0.1 2017/11/12
|
||||
* Version: @(#)win_ddraw.h 1.0.2 2019/10/12
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
*
|
||||
* Copyright 2008-2017 Sarah Walker.
|
||||
* Copyright 2016,2017 Miran Grca.
|
||||
* Copyright 2008-2019 Sarah Walker.
|
||||
* Copyright 2016-2019 Miran Grca.
|
||||
*/
|
||||
#ifndef WIN_DDRAW_H
|
||||
# define WIN_DDRAW_H
|
||||
@@ -32,7 +32,6 @@ extern int ddraw_init(HWND h);
|
||||
extern int ddraw_init_fs(HWND h);
|
||||
extern void ddraw_close(void);
|
||||
extern int ddraw_pause(void);
|
||||
extern void ddraw_take_screenshot(const wchar_t *fn);
|
||||
extern void ddraw_enable(int enable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* we will not use that, but, instead, use a new window which
|
||||
* coverrs the entire desktop.
|
||||
*
|
||||
* Version: @(#)win_sdl.c 1.0.6 2019/03/09
|
||||
* Version: @(#)win_sdl.c 1.0.7 2019/10/12
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Michael Dr<44>ing, <michael@drueing.de>
|
||||
@@ -55,9 +55,6 @@
|
||||
#include <windows.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#define PNG_DEBUG 0
|
||||
#include <png.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
@@ -90,9 +87,6 @@ static int cur_w, cur_h;
|
||||
static volatile int sdl_enabled = 0;
|
||||
static SDL_mutex* sdl_mutex = NULL;
|
||||
|
||||
static png_structp png_ptr;
|
||||
static png_infop info_ptr;
|
||||
|
||||
|
||||
/* Pointers to the real functions. */
|
||||
static void (*sdl_GetVersion)(SDL_version *ver);
|
||||
@@ -522,94 +516,6 @@ sdl_init_fs(HWND h)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sdl_take_screenshot(const wchar_t *fn)
|
||||
{
|
||||
int i, res, x, y, width = 0, height = 0;
|
||||
unsigned char* rgba = NULL;
|
||||
png_bytep *b_rgb = NULL;
|
||||
FILE *fp = NULL;
|
||||
|
||||
sdl_GetWindowSize(sdl_win, &width, &height);
|
||||
|
||||
/* create file */
|
||||
fp = plat_fopen((wchar_t *) fn, (wchar_t *) L"wb");
|
||||
if (!fp) {
|
||||
sdl_log("[sdl_take_screenshot] File %ls could not be opened for writing", fn);
|
||||
return;
|
||||
}
|
||||
|
||||
/* initialize stuff */
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
|
||||
if (!png_ptr) {
|
||||
sdl_log("[sdl_take_screenshot] png_create_write_struct failed");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
sdl_log("[sdl_take_screenshot] png_create_info_struct failed");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height,
|
||||
8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
rgba = (unsigned char *) malloc(width * height * 4);
|
||||
if (rgba == NULL) {
|
||||
sdl_log("[sdl_take_screenshot] Unable to Allocate RGBA Bitmap Memory");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
res = sdl_RenderReadPixels(sdl_render, NULL, SDL_PIXELFORMAT_ABGR8888, rgba, width * 4);
|
||||
if (res) {
|
||||
sdl_log("[sdl_take_screenshot] Error reading render pixels\n");
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
b_rgb = (png_bytep *) malloc(sizeof(png_bytep) * height);
|
||||
if (b_rgb == NULL) {
|
||||
sdl_log("[sdl_take_screenshot] Unable to Allocate RGB Bitmap Memory");
|
||||
free(rgba);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
for (y = 0; y < height; ++y) {
|
||||
b_rgb[y] = (png_byte *) malloc(png_get_rowbytes(png_ptr, info_ptr));
|
||||
for (x = 0; x < width; ++x) {
|
||||
b_rgb[y][(x) * 3 + 0] = rgba[(y * width + x) * 4 + 0];
|
||||
b_rgb[y][(x) * 3 + 1] = rgba[(y * width + x) * 4 + 1];
|
||||
b_rgb[y][(x) * 3 + 2] = rgba[(y * width + x) * 4 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
png_write_image(png_ptr, b_rgb);
|
||||
|
||||
png_write_end(png_ptr, NULL);
|
||||
|
||||
/* cleanup heap allocation */
|
||||
for (i = 0; i < height; i++)
|
||||
if (b_rgb[i]) free(b_rgb[i]);
|
||||
|
||||
if (b_rgb) free(b_rgb);
|
||||
|
||||
if (rgba) free(rgba);
|
||||
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
sdl_pause(void)
|
||||
{
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
*
|
||||
* Definitions for the libSDL2 rendering module.
|
||||
*
|
||||
* Version: @(#)win_sdl.h 1.0.0 2018/05/26
|
||||
* Version: @(#)win_sdl.h 1.0.1 2019/10/12
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Michael Dr<44>ing, <michael@drueing.de>
|
||||
*
|
||||
* Copyright 2018 Fred N. van Kempen.
|
||||
* Copyright 2018 Michael Dr<44>ing.
|
||||
* Copyright 2018,2019 Fred N. van Kempen.
|
||||
* Copyright 2018,2019 Michael Dr<44>ing.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with
|
||||
* or without modification, are permitted provided that the
|
||||
@@ -57,7 +57,5 @@ extern int sdl_pause(void);
|
||||
extern void sdl_resize(int x, int y);
|
||||
extern void sdl_enable(int enable);
|
||||
|
||||
extern void sdl_take_screenshot(const wchar_t *fn);
|
||||
|
||||
|
||||
#endif /*WIN_SDL_H*/
|
||||
|
||||
Reference in New Issue
Block a user