src/main/nacl/SDL_nacl_main.c
author Gabriel Jacobo <gabomdq@gmail.com>
Fri, 20 Jun 2014 10:59:51 -0300
changeset 8877 0d691f3734ac
parent 8851 a7cfe554d337
child 8880 ee5117b56b93
permissions -rw-r--r--
Initialize nacl_io, removes SDL_NaClMount/Umount

It's just easier to use nacl_io's mount/umount directly.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2014 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_NACL
    24 
    25 /* Include the SDL main definition header */
    26 #include "SDL_main.h"
    27 
    28 #include "ppapi_simple/ps_main.h"
    29 #include "ppapi_simple/ps_event.h"
    30 #include "ppapi_simple/ps_interface.h"
    31 #include "nacl_io/nacl_io.h"
    32 
    33 extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
    34 
    35 int
    36 nacl_main(int argc, char *argv[])
    37 {
    38     int status;
    39     PSEvent* ps_event;
    40     PP_Resource event;  
    41     struct PP_Rect rect;
    42     int ready = 0;
    43     const PPB_View *ppb_view = PSInterfaceView();
    44     
    45     /* This is started in a worker thread by ppapi_simple! */
    46     
    47     /* Wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before starting the app */
    48     
    49     PSEventSetFilter(PSE_INSTANCE_DIDCHANGEVIEW);
    50     while (!ready) {
    51         /* Process all waiting events without blocking */
    52         while (!ready && (ps_event = PSEventWaitAcquire()) != NULL) {
    53             event = ps_event->as_resource;
    54             switch(ps_event->type) {
    55                 /* From DidChangeView, contains a view resource */
    56                 case PSE_INSTANCE_DIDCHANGEVIEW:
    57                     ppb_view->GetRect(event, &rect);
    58                     NACL_SetScreenResolution(rect.size.width, rect.size.height, 0);
    59                     ready = 1;
    60                     break;
    61                 default:
    62                     break;
    63             }
    64             PSEventRelease(ps_event);
    65         }
    66     }
    67     
    68     /* Do a default httpfs mount on /, 
    69      * apps can override this by unmounting / 
    70      * and remounting with the desired configuration
    71      */
    72     nacl_io_init_ppapi(PSGetInstanceId(), PSGetInterface);
    73     
    74     umount("/");
    75     mount(
    76         "",  /* source */
    77         "/",  /* target */
    78         "httpfs",  /* filesystemtype */
    79         0,  /* mountflags */
    80         "");  /* data specific to the html5fs type */
    81     
    82     /* Everything is ready, start the user main function */
    83     SDL_SetMainReady();
    84     status = SDL_main(argc, argv);
    85 
    86     return 0;
    87 }
    88 
    89 /* ppapi_simple will start nacl_main in a worker thread */
    90 PPAPI_SIMPLE_REGISTER_MAIN(nacl_main);
    91 
    92 #endif /* SDL_VIDEO_DRIVER_NACL */