summaryrefslogtreecommitdiff
path: root/src/video/windows/SDL_windowsframebuffer.c
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2011-02-04 13:47:02 -0800
committerSam Lantinga <slouken@libsdl.org>2011-02-04 13:47:02 -0800
commit1a56149c954e45b2a0ca7cd5a29592a120ccb330 (patch)
tree42485a50b53d15cf5a6b9a924af422bc286c90cf /src/video/windows/SDL_windowsframebuffer.c
parenta61fb4ebc5b3d78a12aa0d539e6f086576e7e7c3 (diff)
downloadsdl-1a56149c954e45b2a0ca7cd5a29592a120ccb330.tar.gz
Use the exact format of the window if possible, for speed.
Diffstat (limited to 'src/video/windows/SDL_windowsframebuffer.c')
-rwxr-xr-xsrc/video/windows/SDL_windowsframebuffer.c77
1 files changed, 60 insertions, 17 deletions
diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c
index f9f2c5aa2..8b59e273a 100755
--- a/src/video/windows/SDL_windowsframebuffer.c
+++ b/src/video/windows/SDL_windowsframebuffer.c
@@ -23,11 +23,16 @@
#include "SDL_windowsvideo.h"
+#define HAVE_GETDIBITS
int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{
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 */
if (data->mdc) {
@@ -37,25 +42,63 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, voi
DeleteObject(data->hbm);
}
- /* We'll use RGB format for now */
- *format = SDL_PIXELFORMAT_RGB888;
- *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
+ /* 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 */
+ *format = SDL_PIXELFORMAT_RGB888;
+
+ /* Create a new one */
+ SDL_memset(info, 0, size);
+ info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ info->bmiHeader.biPlanes = 1;
+ info->bmiHeader.biBitCount = 32;
+ info->bmiHeader.biCompression = BI_RGB;
+ }
- /* Create a new one */
- info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- info.bmiHeader.biWidth = window->w;
- info.bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */
- info.bmiHeader.biPlanes = 1;
- info.bmiHeader.biBitCount = 32;
- info.bmiHeader.biCompression = BI_RGB;
- info.bmiHeader.biSizeImage = window->h * (*pitch);
- info.bmiHeader.biXPelsPerMeter = 0;
- info.bmiHeader.biYPelsPerMeter = 0;
- info.bmiHeader.biClrUsed = 0;
- info.bmiHeader.biClrImportant = 0;
+ /* Fill in the size information */
+ *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
+ info->bmiHeader.biWidth = window->w;
+ info->bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */
+ info->bmiHeader.biSizeImage = window->h * (*pitch);
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) {
WIN_SetError("Unable to create DIB");
return -1;