SDL  2.0
SDL_windowsframebuffer.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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_internal.h"
22 
23 #if SDL_VIDEO_DRIVER_WINDOWS
24 
25 #include "SDL_windowsvideo.h"
26 
28 {
29  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
30  SDL_bool isstack;
31  size_t size;
32  LPBITMAPINFO info;
33  HBITMAP hbm;
34 
35  /* Free the old framebuffer surface */
36  if (data->mdc) {
37  DeleteDC(data->mdc);
38  }
39  if (data->hbm) {
40  DeleteObject(data->hbm);
41  }
42 
43  /* Find out the format of the screen */
44  size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);
45  info = (LPBITMAPINFO)SDL_small_alloc(Uint8, size, &isstack);
46  if (!info) {
47  return SDL_OutOfMemory();
48  }
49 
50  SDL_memset(info, 0, size);
51  info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
52 
53  /* The second call to GetDIBits() fills in the bitfields */
54  hbm = CreateCompatibleBitmap(data->hdc, 1, 1);
55  GetDIBits(data->hdc, hbm, 0, 0, NULL, info, DIB_RGB_COLORS);
56  GetDIBits(data->hdc, hbm, 0, 0, NULL, info, DIB_RGB_COLORS);
57  DeleteObject(hbm);
58 
60  if (info->bmiHeader.biCompression == BI_BITFIELDS) {
61  int bpp;
62  Uint32 *masks;
63 
64  bpp = info->bmiHeader.biPlanes * info->bmiHeader.biBitCount;
65  masks = (Uint32*)((Uint8*)info + info->bmiHeader.biSize);
66  *format = SDL_MasksToPixelFormatEnum(bpp, masks[0], masks[1], masks[2], 0);
67  }
69  {
70  /* We'll use RGB format for now */
72 
73  /* Create a new one */
74  SDL_memset(info, 0, size);
75  info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
76  info->bmiHeader.biPlanes = 1;
77  info->bmiHeader.biBitCount = 32;
78  info->bmiHeader.biCompression = BI_RGB;
79  }
80 
81  /* Fill in the size information */
82  *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
83  info->bmiHeader.biWidth = window->w;
84  info->bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */
85  info->bmiHeader.biSizeImage = window->h * (*pitch);
86 
87  data->mdc = CreateCompatibleDC(data->hdc);
88  data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0);
89  SDL_small_free(info, isstack);
90 
91  if (!data->hbm) {
92  return WIN_SetError("Unable to create DIB");
93  }
94  SelectObject(data->mdc, data->hbm);
95 
96  return 0;
97 }
98 
99 int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
100 {
101  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
102  int i;
103 
104  for (i = 0; i < numrects; ++i) {
105  BitBlt(data->hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h,
106  data->mdc, rects[i].x, rects[i].y, SRCCOPY);
107  }
108  return 0;
109 }
110 
112 {
113  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
114 
115  if (!data) {
116  /* The window wasn't fully initialized */
117  return;
118  }
119 
120  if (data->mdc) {
121  DeleteDC(data->mdc);
122  data->mdc = NULL;
123  }
124  if (data->hbm) {
125  DeleteObject(data->hbm);
126  data->hbm = NULL;
127  }
128 }
129 
130 #endif /* SDL_VIDEO_DRIVER_WINDOWS */
131 
132 /* vi: set ts=4 sw=4 expandtab: */
#define _THIS
#define BI_BITFIELDS
Definition: SDL_bmp.c:47
#define BI_RGB
Definition: SDL_bmp.c:44
#define SDL_memset
#define SDL_MasksToPixelFormatEnum
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
GLsizeiptr size
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
@ SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:246
@ SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:173
SDL_bool
Definition: SDL_stdinc.h:168
uint8_t Uint8
Definition: SDL_stdinc.h:185
uint32_t Uint32
Definition: SDL_stdinc.h:209
int WIN_SetError(const char *prefix)
void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:163
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
EGLSurface EGLint * rects
Definition: eglext.h:282
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
The type used to identify a window.
Definition: SDL_sysvideo.h:75