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 
103  BitBlt(data->hdc, 0, 0, window->w, window->h, data->mdc, 0, 0, SRCCOPY);
104  return 0;
105 }
106 
108 {
109  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
110 
111  if (!data) {
112  /* The window wasn't fully initialized */
113  return;
114  }
115 
116  if (data->mdc) {
117  DeleteDC(data->mdc);
118  data->mdc = NULL;
119  }
120  if (data->hbm) {
121  DeleteObject(data->hbm);
122  data->hbm = NULL;
123  }
124 }
125 
126 #endif /* SDL_VIDEO_DRIVER_WINDOWS */
127 
128 /* vi: set ts=4 sw=4 expandtab: */
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
WIN_UpdateWindowFramebuffer
int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:386
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_small_free
#define SDL_small_free(ptr, isstack)
Definition: SDL_internal.h:40
if
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
Definition: pixman-arm-neon-asm.h:469
SDL_PIXELFORMAT_RGB888
@ SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:239
NULL
#define NULL
Definition: begin_code.h:167
SDL_WindowData
Definition: SDL_androidwindow.h:38
SDL_MasksToPixelFormatEnum
#define SDL_MasksToPixelFormatEnum
Definition: SDL_dynapi_overrides.h:279
SDL_small_alloc
#define SDL_small_alloc(type, count, pisstack)
Definition: SDL_internal.h:39
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:74
WIN_DestroyWindowFramebuffer
void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
SDL_windowsvideo.h
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
WIN_CreateWindowFramebuffer
int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: SDL_opengl.h:1572
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:540
BI_RGB
#define BI_RGB
Definition: SDL_bmp.c:45
bpp
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
Definition: pixman-arm-neon-asm.h:146
SDL_BYTESPERPIXEL
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
WIN_SetError
int WIN_SetError(const char *prefix)
SDL_Rect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
SDL_PIXELFORMAT_UNKNOWN
@ SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:173
BI_BITFIELDS
#define BI_BITFIELDS
Definition: SDL_bmp.c:48
rects
EGLSurface EGLint * rects
Definition: eglext.h:282
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179