2013-03-02 01:09:58 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 The Chromium Authors
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "platform/CCCommon.h"
|
|
|
|
#include "CCInstance.h"
|
|
|
|
#include "CCApplication.h"
|
|
|
|
#include "CCEGLView.h"
|
2013-03-06 07:50:51 +08:00
|
|
|
|
2013-03-02 01:09:58 +08:00
|
|
|
#include <ppapi/cpp/instance.h>
|
|
|
|
#include <ppapi/cpp/module.h>
|
2013-03-06 07:50:51 +08:00
|
|
|
#include <nacl_io/nacl_io.h>
|
2013-03-02 01:09:58 +08:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
2013-08-22 11:27:31 +08:00
|
|
|
#include <sys/mount.h>
|
2013-03-02 01:09:58 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
|
|
|
CocosPepperInstance::CocosPepperInstance(PP_Instance instance) : pp::Instance(instance),
|
2013-06-15 14:03:30 +08:00
|
|
|
_running(false)
|
2013-03-02 01:09:58 +08:00
|
|
|
{
|
|
|
|
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
|
|
|
|
RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocosPepperInstance::DidChangeView(const pp::View& view)
|
|
|
|
{
|
|
|
|
pp::Rect position = view.GetRect();
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_size == position.size())
|
2013-03-02 01:09:58 +08:00
|
|
|
{
|
|
|
|
// Size did not change.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_running)
|
2013-03-02 01:09:58 +08:00
|
|
|
{
|
|
|
|
CCLOG("DidChangeView (%dx%d) while cocos thread already running",
|
|
|
|
position.size().width(), position.size().height());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_size = position.size();
|
2013-06-20 14:13:12 +08:00
|
|
|
assert(!EGLView::g_instance);
|
|
|
|
EGLView::g_instance = this;
|
2013-06-15 14:03:30 +08:00
|
|
|
CCLOG("DidChangeView %dx%d", _size.width(), _size.height());
|
|
|
|
pthread_create(&_cocos_thread, NULL, cocos_main, this);
|
|
|
|
_running = true;
|
2013-03-02 01:09:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CocosPepperInstance::Init(uint32_t argc, const char* argn[], const char* argv[])
|
|
|
|
{
|
2013-07-24 10:46:13 +08:00
|
|
|
log("CocosPepperInstance::Init: %x %p", pp_instance(),
|
2013-03-06 07:50:51 +08:00
|
|
|
pp::Module::Get()->get_browser_interface());
|
|
|
|
nacl_io_init_ppapi(pp_instance(),
|
|
|
|
pp::Module::Get()->get_browser_interface());
|
2013-03-02 01:09:58 +08:00
|
|
|
|
|
|
|
umount("/");
|
|
|
|
int rtn = mount("Resources", /* source. Use relative URL */
|
|
|
|
"/", /* target */
|
|
|
|
"httpfs", /* filesystemtype */
|
|
|
|
0, /* mountflags */
|
|
|
|
""); /* data */
|
|
|
|
|
|
|
|
if (rtn != 0)
|
|
|
|
{
|
|
|
|
CCLOG("mount failed: %d %s", errno, strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CocosPepperInstance::HandleInputEvent(const pp::InputEvent& event)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (!Application::isRunning())
|
2013-03-02 01:09:58 +08:00
|
|
|
return false;
|
2013-07-12 13:11:21 +08:00
|
|
|
EGLView::getInstance()->AddEvent(event);
|
2013-03-02 01:09:58 +08:00
|
|
|
return true;
|
|
|
|
}
|