相对于Win32来说, NaCl相当于另一个平台, 一些操作系统相关的API需要移植. 除此之外, 参考Technical Overview, 还有一些其它的限制:
这些限制都是为了保证安全性(想想ActiveX为什么失败了)和跨平台(Win/Linux/OSX使用同一个版本)
参考nacl_sdk\vs_addin\examples\hello_nacl_cpp\hello_nacl_cpp.sln
// **** Native Client Framework ****
// The Instance class.
class NaClProjectInstance : public pp::Instance
{
...
};
// The Module class.
class NaClProjectModule : public pp::Module
{
public:
NaClProjectModule() : pp::Module() {}
virtual ~NaClProjectModule() {}
virtual pp::Instance* CreateInstance(PP_Instance instance)
{
return new NaClProjectInstance(instance);
}
};
namespace pp
{
Module* CreateModule()
{
return new NaClProjectModule();
}
}
// Main message loop, Windows style.
while (uMsg.message != WM_QUIT)
{
if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&uMsg);
DispatchMessage(&uMsg);
}
}
return uMsg.wParam;
// Implements Windows window message loop with a callback function.
void NaClProjectInstance::SendCallback(int result)
{
pp::Core* core = pp::Module::Get()->core();
core->CallOnMainThread(
100,
factory_.NewCallback(&NaClProjectInstance::HandleWindowMsg),
result);
}
void HandleWindowMsg(int32_t result)
{
MSG uMsg;
if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&uMsg);
DispatchMessage(&uMsg);
}
SendCallback(0);
}
可以说, 有了PPAPI插件的帮助, 整个移植过程相当的平滑, 可以一步一步进行, 比起什么android/linux/osx平台的移植工作方便太多了.
接下来就是考虑3D游戏相关的移植工作了, 上面提到的很多技术限制也会引起一些传统结构的调整