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