zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_windowsframebuffer.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22 
23 #if SDL_VIDEO_DRIVER_WINDOWS
24 
25 #include "SDL_windowsvideo.h"
26 
27 int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
28 {
30  size_t size;
31  LPBITMAPINFO info;
32  HBITMAP hbm;
33 
34  /* Free the old framebuffer surface */
35  if (data->mdc) {
36  DeleteDC(data->mdc);
37  }
38  if (data->hbm) {
39  DeleteObject(data->hbm);
40  }
41 
42  /* Find out the format of the screen */
43  size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);
44  info = (LPBITMAPINFO)SDL_stack_alloc(Uint8, size);
45 
46  SDL_memset(info, 0, size);
47  info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
48 
49  /* The second call to GetDIBits() fills in the bitfields */
50  hbm = CreateCompatibleBitmap(data->hdc, 1, 1);
51  GetDIBits(data->hdc, hbm, 0, 0, NULL, info, DIB_RGB_COLORS);
52  GetDIBits(data->hdc, hbm, 0, 0, NULL, info, DIB_RGB_COLORS);
53  DeleteObject(hbm);
54 
55  *format = SDL_PIXELFORMAT_UNKNOWN;
56  if (info->bmiHeader.biCompression == BI_BITFIELDS) {
57  int bpp;
58  Uint32 *masks;
59 
60  bpp = info->bmiHeader.biPlanes * info->bmiHeader.biBitCount;
61  masks = (Uint32*)((Uint8*)info + info->bmiHeader.biSize);
62  *format = SDL_MasksToPixelFormatEnum(bpp, masks[0], masks[1], masks[2], 0);
63  }
64  if (*format == SDL_PIXELFORMAT_UNKNOWN)
65  {
66  /* We'll use RGB format for now */
67  *format = SDL_PIXELFORMAT_RGB888;
68 
69  /* Create a new one */
70  SDL_memset(info, 0, size);
71  info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
72  info->bmiHeader.biPlanes = 1;
73  info->bmiHeader.biBitCount = 32;
74  info->bmiHeader.biCompression = BI_RGB;
75  }
76 
77  /* Fill in the size information */
78  *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
79  info->bmiHeader.biWidth = window->w;
80  info->bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */
81  info->bmiHeader.biSizeImage = window->h * (*pitch);
82 
83  data->mdc = CreateCompatibleDC(data->hdc);
84  data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0);
85  SDL_stack_free(info);
86 
87  if (!data->hbm) {
88  return WIN_SetError("Unable to create DIB");
89  }
90  SelectObject(data->mdc, data->hbm);
91 
92  return 0;
93 }
94 
95 int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
96 {
97  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
98 
99  BitBlt(data->hdc, 0, 0, window->w, window->h, data->mdc, 0, 0, SRCCOPY);
100  return 0;
101 }
102 
104 {
105  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
106 
107  if (!data) {
108  /* The window wasn't fully initialized */
109  return;
110  }
111 
112  if (data->mdc) {
113  DeleteDC(data->mdc);
114  data->mdc = NULL;
115  }
116  if (data->hbm) {
117  DeleteObject(data->hbm);
118  data->hbm = NULL;
119  }
120 }
121 
122 #endif /* SDL_VIDEO_DRIVER_WINDOWS */
123 
124 /* vi: set ts=4 sw=4 expandtab: */
#define BI_RGB
Definition: SDL_bmp.c:43
#define NULL
Definition: ftobjs.h:61
#define SDL_stack_free(data)
Definition: SDL_stdinc.h:227
DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
Convert a bpp and RGBA masks to an enumerated pixel format.
Definition: SDL_pixels.c:291
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:123
if(!yyg->yy_init)
int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
#define _THIS
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
Definition: SDL_string.c:261
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
#define BI_BITFIELDS
Definition: SDL_bmp.c:46
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl2ext.h:845
int WIN_SetError(const char *prefix)
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:129
#define SDL_stack_alloc(type, count)
Definition: SDL_stdinc.h:226
void * driverdata
Definition: SDL_sysvideo.h:99
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:63
int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
GLsizei size
Definition: gl2ext.h:1467