src/video/bwindow/SDL_bvideo.cc
author Nathan Heisey <nathanheisey@gmail.com>
Tue, 26 Jul 2011 10:13:34 +0000
changeset 5926 d9d57de9fb4e
parent 5921 4cec9ba57dfb
child 5928 a3a52295bc0d
permissions -rw-r--r--
Fixed seg fault on video quit
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2011 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 
    22 
    23 
    24 
    25 #ifdef __cplusplus
    26 extern "C" {
    27 #endif
    28 
    29 #include "SDL_bwindow.h"
    30 #include "SDL_bclipboard.h"
    31 #include "SDL_bvideo.h"
    32 #include "SDL_bopengl.h"
    33 #include "SDL_bmodes.h"
    34 #include "SDL_bevents.h"
    35 
    36 /* FIXME: Undefined functions */
    37 //    #define BE_PumpEvents NULL
    38     
    39 #if SDL_VIDEO_OPENGL_WGL	/* FIXME: Replace with BeOs's SDL OPENGL stuff */
    40 //    #define BE_GL_LoadLibrary NULL
    41 //    #define BE_GL_GetProcAddress NULL
    42     #define BE_GL_UnloadLibrary NULL
    43     #define BE_GL_CreateContext NULL
    44 //    #define BE_GL_MakeCurrent NULL
    45     #define BE_GL_SetSwapInterval NULL
    46     #define BE_GL_GetSwapInterval NULL
    47     #define BE_GL_SwapWindow NULL
    48     #define BE_GL_DeleteContext NULL
    49 #endif
    50     #define BE_StartTextInput NULL
    51     #define BE_StopTextInput NULL
    52     #define BE_SetTextInputRect NULL
    53 
    54 //    #define BE_DeleteDevice NULL
    55 
    56 /* End undefined functions */
    57 
    58 static SDL_VideoDevice *
    59 BE_CreateDevice(int devindex)
    60 {
    61     SDL_VideoDevice *device;
    62     /*SDL_VideoData *data;*/
    63 
    64     /* Initialize all variables that we clean on shutdown */
    65     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    66 #if 0
    67     if (device) {
    68         data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
    69     } else {
    70         data = NULL;
    71     }
    72     if (!data) {
    73         SDL_OutOfMemory();
    74         if (device) {
    75             SDL_free(device);
    76         }
    77         return NULL;
    78     }
    79 #endif
    80     device->driverdata = NULL; /*data;*/
    81 
    82 /* TODO: Figure out what sort of initialization needs to go here */
    83 
    84     /* Set the function pointers */
    85     device->VideoInit = BE_VideoInit;
    86     device->VideoQuit = BE_VideoQuit;
    87     device->GetDisplayBounds = BE_GetDisplayBounds;
    88     device->GetDisplayModes = BE_GetDisplayModes;
    89     device->SetDisplayMode = BE_SetDisplayMode;
    90     device->PumpEvents = BE_PumpEvents;
    91 
    92     device->CreateWindow = BE_CreateWindow;
    93     device->CreateWindowFrom = BE_CreateWindowFrom;
    94     device->SetWindowTitle = BE_SetWindowTitle;
    95     device->SetWindowIcon = BE_SetWindowIcon;
    96     device->SetWindowPosition = BE_SetWindowPosition;
    97     device->SetWindowSize = BE_SetWindowSize;
    98     device->ShowWindow = BE_ShowWindow;
    99     device->HideWindow = BE_HideWindow;
   100     device->RaiseWindow = BE_RaiseWindow;
   101     device->MaximizeWindow = BE_MaximizeWindow;
   102     device->MinimizeWindow = BE_MinimizeWindow;
   103     device->RestoreWindow = BE_RestoreWindow;
   104     device->SetWindowFullscreen = BE_SetWindowFullscreen;
   105     device->SetWindowGammaRamp = BE_SetWindowGammaRamp;
   106     device->GetWindowGammaRamp = BE_GetWindowGammaRamp;
   107     device->SetWindowGrab = BE_SetWindowGrab;
   108     device->DestroyWindow = BE_DestroyWindow;
   109     device->GetWindowWMInfo = BE_GetWindowWMInfo;
   110     device->CreateWindowFramebuffer = BE_CreateWindowFramebuffer;
   111     device->UpdateWindowFramebuffer = BE_UpdateWindowFramebuffer;
   112     device->DestroyWindowFramebuffer = BE_DestroyWindowFramebuffer;
   113     
   114     device->shape_driver.CreateShaper = NULL;
   115     device->shape_driver.SetWindowShape = NULL;
   116     device->shape_driver.ResizeWindowShape = NULL;
   117     
   118 #if SDL_VIDEO_OPENGL_WGL	/* FIXME: Replace with BeOs's SDL OPENGL stuff */
   119     device->GL_LoadLibrary = BE_GL_LoadLibrary;
   120     device->GL_GetProcAddress = BE_GL_GetProcAddress;
   121     device->GL_UnloadLibrary = BE_GL_UnloadLibrary;
   122     device->GL_CreateContext = BE_GL_CreateContext;
   123     device->GL_MakeCurrent = BE_GL_MakeCurrent;
   124     device->GL_SetSwapInterval = BE_GL_SetSwapInterval;
   125     device->GL_GetSwapInterval = BE_GL_GetSwapInterval;
   126     device->GL_SwapWindow = BE_GL_SwapWindow;
   127     device->GL_DeleteContext = BE_GL_DeleteContext;
   128 #endif
   129     device->StartTextInput = BE_StartTextInput;
   130     device->StopTextInput = BE_StopTextInput;
   131     device->SetTextInputRect = BE_SetTextInputRect;
   132 
   133     device->SetClipboardText = BE_SetClipboardText;
   134     device->GetClipboardText = BE_GetClipboardText;
   135     device->HasClipboardText = BE_HasClipboardText;
   136 
   137     device->free = BE_DeleteDevice;
   138 
   139     return device;
   140 }
   141 
   142 VideoBootStrap BWINDOW_bootstrap = {
   143 	"bwindow", "BDirectWindow graphics",
   144 	BE_Available, BE_CreateDevice
   145 };
   146 
   147 static void BE_DeleteDevice(SDL_VideoDevice * device)
   148 {
   149 	SDL_free(device->driverdata);
   150 	SDL_free(device);
   151 }
   152 
   153 /* FIXME: This is the 1.2 function at the moment.  Read through it and
   154   o understand what it does. */
   155 int BE_VideoInit(_THIS)
   156 {
   157 	/* Initialize the Be Application for appserver interaction */
   158 	if (SDL_InitBeApp() < 0) {
   159 		return -1;
   160 	}
   161 	
   162 	BE_InitModes(_this);
   163 
   164 #if SDL_VIDEO_OPENGL
   165         /* testgl application doesn't load library, just tries to load symbols */
   166         /* is it correct? if so we have to load library here */
   167     BE_GL_LoadLibrary(_this, NULL);
   168 #endif
   169 
   170         /* Fill in some window manager capabilities */
   171 //    _this->info.wm_available = 1;
   172 
   173         /* We're done! */
   174     return (0);
   175 }
   176 
   177 static int BE_Available(void)
   178 {
   179     return (1);
   180 }
   181 
   182 void BE_VideoQuit(_THIS)
   183 {
   184 
   185 #if 0
   186         SDL_Win->Quit();
   187         SDL_Win = NULL;
   188 #endif
   189 #if 0
   190         if (SDL_BlankCursor != NULL) {
   191             BE_FreeWMCursor(_this, SDL_BlankCursor);
   192             SDL_BlankCursor = NULL;
   193         }
   194 #endif
   195 
   196     BE_QuitModes(_this);
   197 
   198 #if SDL_VIDEO_OPENGL
   199 //    if (_this->gl_config.dll_handle != NULL)
   200 //        unload_add_on((image_id) _this->gl_config.dll_handle);
   201 #endif
   202 
   203     SDL_QuitBeApp();
   204 }
   205 
   206 #ifdef __cplusplus
   207 }
   208 #endif