Added the Windows framebuffer implementation.
authorSam Lantinga <slouken@libsdl.org>
Fri, 04 Feb 2011 12:29:58 -0800
changeset 51759b2e99ebd099
parent 5174 b9cf75615028
child 5176 6d37aa594ecd
Added the Windows framebuffer implementation.
This actually ends up being faster than Direct3D with a dynamic texture. (???)
src/video/windows/SDL_windowsframebuffer.c
src/video/windows/SDL_windowsframebuffer.h
src/video/windows/SDL_windowsvideo.c
src/video/windows/SDL_windowswindow.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/windows/SDL_windowsframebuffer.c	Fri Feb 04 12:29:58 2011 -0800
     1.3 @@ -0,0 +1,90 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2010 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#include "SDL_windowsvideo.h"
    1.28 +
    1.29 +
    1.30 +int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
    1.31 +{
    1.32 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.33 +    BITMAPINFO info;
    1.34 +
    1.35 +    /* Free the old framebuffer surface */
    1.36 +    if (data->mdc) {
    1.37 +        DeleteDC(data->mdc);
    1.38 +    }
    1.39 +    if (data->hbm) {
    1.40 +        DeleteObject(data->hbm);
    1.41 +    }
    1.42 +
    1.43 +    /* We'll use RGB format for now */
    1.44 +    *format = SDL_PIXELFORMAT_RGB888;
    1.45 +    *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
    1.46 +
    1.47 +    /* Create a new one */
    1.48 +    info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    1.49 +    info.bmiHeader.biWidth = window->w;
    1.50 +    info.bmiHeader.biHeight = -window->h;	/* negative for topdown bitmap */
    1.51 +    info.bmiHeader.biPlanes = 1;
    1.52 +    info.bmiHeader.biBitCount = 32;
    1.53 +    info.bmiHeader.biCompression = BI_RGB;
    1.54 +    info.bmiHeader.biSizeImage = window->h * (*pitch);
    1.55 +    info.bmiHeader.biXPelsPerMeter = 0;
    1.56 +    info.bmiHeader.biYPelsPerMeter = 0;
    1.57 +    info.bmiHeader.biClrUsed = 0;
    1.58 +    info.bmiHeader.biClrImportant = 0;
    1.59 +
    1.60 +    data->mdc = CreateCompatibleDC(data->hdc);
    1.61 +    data->hbm = CreateDIBSection(data->hdc, &info, DIB_RGB_COLORS, pixels, NULL, 0);
    1.62 +    if (!data->hbm) {
    1.63 +        WIN_SetError("Unable to create DIB");
    1.64 +        return -1;
    1.65 +    }
    1.66 +    SelectObject(data->mdc, data->hbm);
    1.67 +
    1.68 +    return 0;
    1.69 +}
    1.70 +
    1.71 +int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects)
    1.72 +{
    1.73 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.74 +
    1.75 +    BitBlt(data->hdc, 0, 0, window->w, window->h, data->mdc, 0, 0, SRCCOPY);
    1.76 +    return 0;
    1.77 +}
    1.78 +
    1.79 +void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
    1.80 +{
    1.81 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.82 +
    1.83 +    if (data->mdc) {
    1.84 +        DeleteDC(data->mdc);
    1.85 +        data->mdc = NULL;
    1.86 +    }
    1.87 +    if (data->hbm) {
    1.88 +        DeleteObject(data->hbm);
    1.89 +        data->hbm = NULL;
    1.90 +    }
    1.91 +}
    1.92 +
    1.93 +/* vi: set ts=4 sw=4 expandtab: */
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/video/windows/SDL_windowsframebuffer.h	Fri Feb 04 12:29:58 2011 -0800
     2.3 @@ -0,0 +1,28 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2010 Sam Lantinga
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +*/
    2.25 +#include "SDL_config.h"
    2.26 +
    2.27 +extern int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
    2.28 +extern int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects);
    2.29 +extern void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
    2.30 +
    2.31 +/* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/video/windows/SDL_windowsvideo.c	Fri Feb 04 12:26:01 2011 -0800
     3.2 +++ b/src/video/windows/SDL_windowsvideo.c	Fri Feb 04 12:29:58 2011 -0800
     3.3 @@ -28,6 +28,7 @@
     3.4  #include "../SDL_pixels_c.h"
     3.5  
     3.6  #include "SDL_windowsvideo.h"
     3.7 +#include "SDL_windowsframebuffer.h"
     3.8  #include "SDL_windowsshape.h"
     3.9  
    3.10  /* Initialization/Query functions */
    3.11 @@ -128,6 +129,9 @@
    3.12      device->SetWindowGrab = WIN_SetWindowGrab;
    3.13      device->DestroyWindow = WIN_DestroyWindow;
    3.14      device->GetWindowWMInfo = WIN_GetWindowWMInfo;
    3.15 +    device->CreateWindowFramebuffer = WIN_CreateWindowFramebuffer;
    3.16 +    device->UpdateWindowFramebuffer = WIN_UpdateWindowFramebuffer;
    3.17 +    device->DestroyWindowFramebuffer = WIN_DestroyWindowFramebuffer;
    3.18      
    3.19      device->shape_driver.CreateShaper = Win32_CreateShaper;
    3.20      device->shape_driver.SetWindowShape = Win32_SetWindowShape;
     4.1 --- a/src/video/windows/SDL_windowswindow.h	Fri Feb 04 12:26:01 2011 -0800
     4.2 +++ b/src/video/windows/SDL_windowswindow.h	Fri Feb 04 12:29:58 2011 -0800
     4.3 @@ -38,6 +38,8 @@
     4.4      SDL_Window *window;
     4.5      HWND hwnd;
     4.6      HDC hdc;
     4.7 +    HDC mdc;
     4.8 +    HBITMAP hbm;
     4.9      WNDPROC wndproc;
    4.10      SDL_bool created;
    4.11      int mouse_pressed;