Commit 1b6243d5 authored by Sam Lantinga's avatar Sam Lantinga

Use the exact format of the window if possible, for speed.

parent d9aa5839
...@@ -23,11 +23,16 @@ ...@@ -23,11 +23,16 @@
#include "SDL_windowsvideo.h" #include "SDL_windowsvideo.h"
#define HAVE_GETDIBITS
int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{ {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
BITMAPINFO info; size_t size;
LPBITMAPINFO info;
#ifdef HAVE_GETDIBITS
HBITMAP hbm;
#endif
/* Free the old framebuffer surface */ /* Free the old framebuffer surface */
if (data->mdc) { if (data->mdc) {
...@@ -37,25 +42,63 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi ...@@ -37,25 +42,63 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi
DeleteObject(data->hbm); DeleteObject(data->hbm);
} }
/* Find out the format of the screen */
size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);
info = (LPBITMAPINFO)SDL_stack_alloc(Uint8, size);
#ifdef HAVE_GETDIBITS
SDL_memset(info, 0, size);
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
/* The second call to GetDIBits() fills in the bitfields */
hbm = CreateCompatibleBitmap(data->hdc, 1, 1);
GetDIBits(data->hdc, hbm, 0, 0, NULL, info, DIB_RGB_COLORS);
GetDIBits(data->hdc, hbm, 0, 0, NULL, info, DIB_RGB_COLORS);
DeleteObject(hbm);
*format = SDL_PIXELFORMAT_UNKNOWN;
if (info->bmiHeader.biCompression == BI_BITFIELDS) {
Uint32 *masks;
masks = (Uint32*)((Uint8*)info + info->bmiHeader.biSize);
if (masks[0] == 0x00FF0000 && masks[2] == 0x000000FF) {
*format = SDL_PIXELFORMAT_RGB888;
} else if (masks[0] == 0x000000FF && masks[2] == 0x00FF0000) {
*format = SDL_PIXELFORMAT_BGR888;
} else if (masks[0] == 0xF800 && masks[2] == 0x001F) {
*format = SDL_PIXELFORMAT_RGB565;
} else if (masks[0] == 0x001F && masks[2] == 0xF800) {
*format = SDL_PIXELFORMAT_BGR565;
} else if (masks[0] == 0x7C00 && masks[2] == 0x001F) {
*format = SDL_PIXELFORMAT_RGB555;
} else if (masks[0] == 0x001F && masks[2] == 0x7C00) {
*format = SDL_PIXELFORMAT_BGR555;
}
}
if (*format == SDL_PIXELFORMAT_UNKNOWN)
#endif
{
/* We'll use RGB format for now */ /* We'll use RGB format for now */
*format = SDL_PIXELFORMAT_RGB888; *format = SDL_PIXELFORMAT_RGB888;
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
/* Create a new one */ /* Create a new one */
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); SDL_memset(info, 0, size);
info.bmiHeader.biWidth = window->w; info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */ info->bmiHeader.biPlanes = 1;
info.bmiHeader.biPlanes = 1; info->bmiHeader.biBitCount = 32;
info.bmiHeader.biBitCount = 32; info->bmiHeader.biCompression = BI_RGB;
info.bmiHeader.biCompression = BI_RGB; }
info.bmiHeader.biSizeImage = window->h * (*pitch);
info.bmiHeader.biXPelsPerMeter = 0; /* Fill in the size information */
info.bmiHeader.biYPelsPerMeter = 0; *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
info.bmiHeader.biClrUsed = 0; info->bmiHeader.biWidth = window->w;
info.bmiHeader.biClrImportant = 0; info->bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */
info->bmiHeader.biSizeImage = window->h * (*pitch);
data->mdc = CreateCompatibleDC(data->hdc); data->mdc = CreateCompatibleDC(data->hdc);
data->hbm = CreateDIBSection(data->hdc, &info, DIB_RGB_COLORS, pixels, NULL, 0); data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0);
SDL_stack_free(info);
if (!data->hbm) { if (!data->hbm) {
WIN_SetError("Unable to create DIB"); WIN_SetError("Unable to create DIB");
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment