Ignore:
Timestamp:
Jun 5, 2012, 8:15:56 PM (9 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.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.