src/video/windows/SDL_windowsframebuffer.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 16 Nov 2019 22:45:49 -0800
changeset 13252 900d20d46990
parent 12503 806492103856
permissions -rw-r--r--
Fixed bug 4814 - Missing scancodes on Linux

Michael Roe

The mappings for keyboard scancodes on Linux do not include keypad left and right parentheses (used on some Microsoft keyboard), keypad plus/minus, LANG1 and LANG2 (used on Korean keyboards), XK86MenuKB, and F20 (remapped to Audio Mic Mute in the usual X11 config).
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2019 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 
    27 int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
    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 
    59     *format = SDL_PIXELFORMAT_UNKNOWN;
    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     }
    68     if (*format == SDL_PIXELFORMAT_UNKNOWN)
    69     {
    70         /* We'll use RGB format for now */
    71         *format = SDL_PIXELFORMAT_RGB888;
    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 
   107 void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
   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: */