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.
gabomdq@8833
     1
/*
gabomdq@8833
     2
  Simple DirectMedia Layer
gabomdq@8833
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
gabomdq@8833
     4
gabomdq@8833
     5
  This software is provided 'as-is', without any express or implied
gabomdq@8833
     6
  warranty.  In no event will the authors be held liable for any damages
gabomdq@8833
     7
  arising from the use of this software.
gabomdq@8833
     8
gabomdq@8833
     9
  Permission is granted to anyone to use this software for any purpose,
gabomdq@8833
    10
  including commercial applications, and to alter it and redistribute it
gabomdq@8833
    11
  freely, subject to the following restrictions:
gabomdq@8833
    12
gabomdq@8833
    13
  1. The origin of this software must not be misrepresented; you must not
gabomdq@8833
    14
     claim that you wrote the original software. If you use this software
gabomdq@8833
    15
     in a product, an acknowledgment in the product documentation would be
gabomdq@8833
    16
     appreciated but is not required.
gabomdq@8833
    17
  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@8833
    18
     misrepresented as being the original software.
gabomdq@8833
    19
  3. This notice may not be removed or altered from any source distribution.
gabomdq@8833
    20
*/
gabomdq@8833
    21
#include "../../SDL_internal.h"
gabomdq@8833
    22
gabomdq@8833
    23
#if SDL_VIDEO_DRIVER_NACL
gabomdq@8833
    24
gabomdq@8833
    25
/* Include the SDL main definition header */
gabomdq@8833
    26
#include "SDL_main.h"
gabomdq@8833
    27
gabomdq@8833
    28
#include "ppapi_simple/ps_main.h"
gabomdq@8833
    29
#include "ppapi_simple/ps_event.h"
gabomdq@8833
    30
#include "ppapi_simple/ps_interface.h"
gabomdq@8877
    31
#include "nacl_io/nacl_io.h"
gabomdq@8833
    32
gabomdq@8833
    33
extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
gabomdq@8833
    34
gabomdq@8833
    35
int
gabomdq@8833
    36
nacl_main(int argc, char *argv[])
gabomdq@8833
    37
{
gabomdq@8833
    38
    int status;
gabomdq@8833
    39
    PSEvent* ps_event;
gabomdq@8833
    40
    PP_Resource event;  
gabomdq@8833
    41
    struct PP_Rect rect;
gabomdq@8833
    42
    int ready = 0;
gabomdq@8833
    43
    const PPB_View *ppb_view = PSInterfaceView();
gabomdq@8833
    44
    
gabomdq@8833
    45
    /* This is started in a worker thread by ppapi_simple! */
gabomdq@8833
    46
    
gabomdq@8833
    47
    /* Wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before starting the app */
gabomdq@8833
    48
    
gabomdq@8833
    49
    PSEventSetFilter(PSE_INSTANCE_DIDCHANGEVIEW);
gabomdq@8833
    50
    while (!ready) {
gabomdq@8833
    51
        /* Process all waiting events without blocking */
gabomdq@8833
    52
        while (!ready && (ps_event = PSEventWaitAcquire()) != NULL) {
gabomdq@8833
    53
            event = ps_event->as_resource;
gabomdq@8833
    54
            switch(ps_event->type) {
gabomdq@8833
    55
                /* From DidChangeView, contains a view resource */
gabomdq@8833
    56
                case PSE_INSTANCE_DIDCHANGEVIEW:
gabomdq@8833
    57
                    ppb_view->GetRect(event, &rect);
gabomdq@8833
    58
                    NACL_SetScreenResolution(rect.size.width, rect.size.height, 0);
gabomdq@8833
    59
                    ready = 1;
gabomdq@8833
    60
                    break;
gabomdq@8833
    61
                default:
gabomdq@8833
    62
                    break;
gabomdq@8833
    63
            }
gabomdq@8833
    64
            PSEventRelease(ps_event);
gabomdq@8833
    65
        }
gabomdq@8833
    66
    }
gabomdq@8833
    67
    
gabomdq@8851
    68
    /* Do a default httpfs mount on /, 
gabomdq@8851
    69
     * apps can override this by unmounting / 
gabomdq@8851
    70
     * and remounting with the desired configuration
gabomdq@8851
    71
     */
gabomdq@8877
    72
    nacl_io_init_ppapi(PSGetInstanceId(), PSGetInterface);
gabomdq@8877
    73
    
gabomdq@8877
    74
    umount("/");
gabomdq@8877
    75
    mount(
gabomdq@8851
    76
        "",  /* source */
gabomdq@8851
    77
        "/",  /* target */
gabomdq@8851
    78
        "httpfs",  /* filesystemtype */
gabomdq@8851
    79
        0,  /* mountflags */
gabomdq@8851
    80
        "");  /* data specific to the html5fs type */
gabomdq@8851
    81
    
gabomdq@8833
    82
    /* Everything is ready, start the user main function */
gabomdq@8833
    83
    SDL_SetMainReady();
gabomdq@8833
    84
    status = SDL_main(argc, argv);
gabomdq@8833
    85
gabomdq@8833
    86
    return 0;
gabomdq@8833
    87
}
gabomdq@8833
    88
gabomdq@8833
    89
/* ppapi_simple will start nacl_main in a worker thread */
gabomdq@8833
    90
PPAPI_SIMPLE_REGISTER_MAIN(nacl_main);
gabomdq@8833
    91
gabomdq@8833
    92
#endif /* SDL_VIDEO_DRIVER_NACL */