SDL_windowsframebuffer.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WINDOWS
#include "SDL_windowsvideo.h"
int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
size_t size;
LPBITMAPINFO info;
HBITMAP hbm;
/* Free the old framebuffer surface */
if (data->mdc) {
DeleteDC(data->mdc);
}
if (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);
if (!info) {
return SDL_OutOfMemory();
}
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) {
int bpp;
Uint32 *masks;
bpp = info->bmiHeader.biPlanes * info->bmiHeader.biBitCount;
masks = (Uint32*)((Uint8*)info + info->bmiHeader.biSize);
*format = SDL_MasksToPixelFormatEnum(bpp, masks[0], masks[1], masks[2], 0);
}
if (*format == SDL_PIXELFORMAT_UNKNOWN)
{
/* 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;
}
/* 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);
SDL_stack_free(info);
if (!data->hbm) {
return WIN_SetError("Unable to create DIB");
}
SelectObject(data->mdc, data->hbm);
return 0;
}
int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
BitBlt(data->hdc, 0, 0, window->w, window->h, data->mdc, 0, 0, SRCCOPY);
return 0;
}
void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (!data) {
/* The window wasn't fully initialized */
return;
}
if (data->mdc) {
DeleteDC(data->mdc);
data->mdc = NULL;
}
if (data->hbm) {
DeleteObject(data->hbm);
data->hbm = NULL;
}
}
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
/* vi: set ts=4 sw=4 expandtab: */
BI_RGB
#define BI_RGB
Definition: SDL_bmp.c:44
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1565
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:157
SDL_Window::w
int w
Definition: SDL_sysvideo.h:78
SDL_WindowData::hbm
HBITMAP hbm
Definition: SDL_windowswindow.h:36
window
SDL_Window * window
Definition: testautomation_render.c:26
SDL_MasksToPixelFormatEnum
#define SDL_MasksToPixelFormatEnum
Definition: SDL_dynapi_overrides.h:285
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
SDL_BYTESPERPIXEL
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:127
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1565
SDL_WindowData::hdc
HDC hdc
Definition: SDL_windowswindow.h:34
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:537
SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:235
SDL_WindowData
Definition: SDL_androidwindow.h:34
WIN_CreateWindowFramebuffer
int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
WIN_DestroyWindowFramebuffer
void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_stack_alloc
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:326
SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:172
BI_BITFIELDS
#define BI_BITFIELDS
Definition: SDL_bmp.c:47
SDL_Window::h
int h
Definition: SDL_sysvideo.h:78
NULL
#define NULL
Definition: begin_code.h:143
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_WindowData::mdc
HDC mdc
Definition: SDL_windowswindow.h:35
WIN_SetError
int WIN_SetError(const char *prefix)
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:71
rects
SDL_Rect rects[MAX_RECTS]
Definition: testintersections.c:129
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:106
SDL_stack_free
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:327
SDL_windowsvideo.h
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
WIN_UpdateWindowFramebuffer
int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)