Changeset 1440


Ignore:
Timestamp:
Jun 5, 2012, 8:15:56 PM (8 years ago)
Author:
sam
Message:

nacl: NaCl binaries no longer need a modified main() to work, the NaCl
instance object takes care of everything for us.

Location:
trunk/src
Files:
1 added
1 deleted
3 edited
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r1406 r1440  
    7272if USE_NACL
    7373nacl_sources = \
    74     platform/nacl/naclapp.cpp platform/nacl/naclapp.h \
    75     platform/nacl/nacl_instance.cpp platform/nacl/nacl_instance.h \
    76     platform/nacl/nacl_module.cpp \
     74    platform/nacl/nacl-app.cpp platform/nacl/nacl-app.h \
     75    platform/nacl/nacl-instance.cpp platform/nacl/nacl-instance.h \
     76    platform/nacl/nacl-module.cpp \
    7777    platform/nacl/opengl_context.cpp platform/nacl/opengl_context.h \
    7878    platform/nacl/opengl_context_ptrs.h
  • trunk/src/application/application.cpp

    r1219 r1440  
    2121#   include "platform/xbox/xboxapp.h"
    2222#elif defined __native_client__
    23 #   include "platform/nacl/naclapp.h"
     23#   include "platform/nacl/nacl-app.h"
    2424#elif defined __ANDROID__
    2525#   include "platform/android/androidapp.h"
  • trunk/src/platform/nacl/nacl-app.cpp

    r1439 r1440  
    1313#endif
    1414
    15 #if defined __native_client__
    16 #   include <ppapi/cpp/instance.h>
    17 #   include <ppapi/cpp/module.h>
    18 #   include <ppapi/cpp/var.h>
    19 #endif
     15#include "core.h"
    2016
    21 #include "core.h"
    22 #include "lolgl.h"
    23 #include "naclapp.h"
     17#include "nacl-app.h"
     18#include "nacl-instance.h"
    2419
    2520namespace lol
     
    4641    data(new NaClAppData())
    4742{
     43    Ticker::Setup(fps);
    4844#if defined __native_client__
    4945#endif
     
    5753void NaClApp::Run()
    5854{
    59     while (!Ticker::Finished())
    60     {
    61         /* Tick the renderer, show the frame and clamp to desired framerate. */
    62         Ticker::TickDraw();
     55#if defined __native_client__
     56    NaClInstance::MainSignal();
     57#endif
    6358
    64 #if defined __native_client__
    65 #endif
    66     }
     59    /* Wait forever */
     60    Queue<int, 1> q;
     61    q.Pop();
    6762}
    6863
  • trunk/src/platform/nacl/nacl-instance.cpp

    r1439 r1440  
    1111#include <cstring>
    1212#include <string>
    13 #include <vector>
    1413
    1514#include <ppapi/cpp/rect.h>
     
    2120
    2221#include "core.h"
    23 #include "debug/quad.h"
    2422
    25 #include "platform/nacl/nacl_instance.h"
     23#include "platform/nacl/nacl-instance.h"
    2624#include "platform/nacl/opengl_context.h"
    2725
     
    4745{
    4846    // Destroy the cube view while GL context is current.
    49     opengl_context_->MakeContextCurrent(this);
     47    m_opengl_ctx->MakeContextCurrent(this);
    5048}
    5149
     
    8583}
    8684
     85Mutex NaClInstance::main_mutex;
     86Queue<NaClInstance::Args *, 1> NaClInstance::main_queue;
     87
    8788bool NaClInstance::Init(uint32_t argc,
    8889                        const char* /* argn */[],
    8990                        const char* argv[])
    9091{
    91     Ticker::Setup(60.0f);
    92 
    93     /* Call the user's main() function. FIXME: run it in a thread */
     92    /* Ensure only one NaClInstance does Init() at the same time. */
     93    main_mutex.Lock();
    9494    char *env[] = { NULL };
    95     lol_nacl_main();
    96     lol_nacl_main(argc, const_cast<char **>(argv));
    97     lol_nacl_main(argc, const_cast<char **>(argv), (char **)env);
     95    Args arglist(argc, const_cast<char **>(argv), const_cast<char **>(env));
     96    main_queue.Push(&arglist);
     97    m_main_thread = new Thread(MainRun, NULL);
     98    /* Push so that only MainSignal() can unblock us */
     99    main_queue.Push(NULL);
     100    main_queue.Push(NULL);
     101    main_mutex.Unlock();
    98102
    99103    // My timer callback
     
    108112}
    109113
    110 void NaClInstance::RunMain(uint32_t argc,
    111                            const char* /* argn */[],
    112                            const char* argv[])
     114void * NaClInstance::MainRun(void *data)
    113115{
     116    Args *arglist = main_queue.Pop();
    114117
     118    /* Call the user's main() function. One of these will work. */
     119    lol_nacl_main();
     120    lol_nacl_main(arglist->m_argc, arglist->m_argv);
     121    lol_nacl_main(arglist->m_argc, arglist->m_argv, arglist->m_env);
     122
     123    return NULL;
     124}
     125
     126void NaClInstance::MainSignal()
     127{
     128    /* FIXME: find something more elegant. */
     129    main_queue.Pop();
     130    main_queue.Pop();
    115131}
    116132
     
    130146    m_size = ivec2(position.size().width(), position.size().height());
    131147
    132     if (opengl_context_ == NULL)
    133         opengl_context_.reset(new OpenGLContext(this));
    134     opengl_context_->InvalidateContext(this);
    135     opengl_context_->ResizeContext(position.size());
    136     if (!opengl_context_->MakeContextCurrent(this))
     148    if (m_opengl_ctx == NULL)
     149        m_opengl_ctx.reset(new OpenGLContext(this));
     150    m_opengl_ctx->InvalidateContext(this);
     151    m_opengl_ctx->ResizeContext(position.size());
     152    if (!m_opengl_ctx->MakeContextCurrent(this))
    137153        return;
    138154
     
    152168        break;
    153169    case PP_INPUTEVENT_TYPE_MOUSEMOVE:
    154         Input::SetMousePos(ivec2(pp::MouseInputEvent(event).GetPosition().x(), opengl_context_->GetSize().height() - 1 - pp::MouseInputEvent(event).GetPosition().y()));
     170        Input::SetMousePos(ivec2(pp::MouseInputEvent(event).GetPosition().x(), m_opengl_ctx->GetSize().height() - 1 - pp::MouseInputEvent(event).GetPosition().y()));
    155171        break;
    156172    default:
     
    162178void NaClInstance::DrawSelf()
    163179{
    164     if (opengl_context_ == NULL)
     180    if (m_opengl_ctx == NULL)
    165181        return;
    166182
    167     opengl_context_->MakeContextCurrent(this);
     183    m_opengl_ctx->MakeContextCurrent(this);
    168184    Ticker::TickDraw();
    169     opengl_context_->FlushContext();
     185    m_opengl_ctx->FlushContext();
    170186}
    171187
  • trunk/src/platform/nacl/nacl-module.cpp

    r1439 r1440  
    1212
    1313#include "core.h"
    14 #include "lolgl.h"
     14#include "lolgl.h" /* needed for GL_TRUE */
    1515
    16 #include "platform/nacl/nacl_instance.h"
     16#include "platform/nacl/nacl-instance.h"
    1717
    1818/// The Module class.  The browser calls the CreateInstance() method to create
  • trunk/src/platform/nacl/opengl_context.h

    r1087 r1440  
    7070
    7171  /// The PP_Resource needed to make GLES2 calls through the Pepper interface.
    72   const PP_Resource gl_context() const {
     72  PP_Resource gl_context() const {
    7373    return context_.pp_resource();
    7474  }
Note: See TracChangeset for help on using the changeset viewer.