/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// This project demonstrates how to migrate a Windows desktop app to Native
// Client, running first as a Win32 application (define STEP1), then as a PPAPI
// plugin (define STEP2 through STEP6), and finally as a Native Client module.
// Start with STEP1 defined and the defines for STEP2 through STEP6 commented
// out. For each step in the process, un-comment the next #define, leaving the
// previous ones on. Ready, set, port!
// *** SELECT THE WIN32 PLATFORM AND RUN WITH #define STEP1 ONLY ***
#define STEP1
// Launches the original Windows desktop application, Hello World, which runs
// as WinMain. STEP1 encloses Windows-specific functions that are used with
// the WIN32 and PPAPI platforms. These will be removed when the full PPAPI
// port is finished (STEP6)
// *** SELECT THE PPAPI PLATFORM ***
//#define STEP2
// What Changed: The platform launches Chrome, which will then load a Native
// Client Module. STEP2 encloses the Native Client module APIs needed to link
// any app to the browser. The module does nothing except report
// starting/ending the function Instance_DidCreate. The Windows app does not
// run because it is not being called.
//#define STEP3
// What changed: Replace WinMain with WndProc, and call it from
// Instance_DidCreate, launching hello_nacl in its own window.
// Since WndProc spins in its message loop, the call to Instance_DidCreate
// never returns.
// Close the hello_nacl window and the module initialization will finish.
//#define STEP4
// What changed: In WndProc replace the message loop with a callback function.
// Now the app window and the Native Client module are running concurrently.
//#define STEP5
// What changed: Instance_DidCreate calls InitInstanceInBrowserWindow rather
// than InitInstanceInPCWindow.
// The InitInstanceInBrowserWindow uses postMessage to place text (now "Hello,
// Native Client") in the web page instead of opening and writing to a window.
//#define STEP6
// What changed: All the Windows code is def'd out, to prove we are
// PPAPI-compliant. The functional code that is running is the same as STEP5.
// *** SELECT THE NACL64 PLATFORM AND RUN ***
// What changed: The code is the same as STEP6, but you are using the SDK
// toolchain to compile it into a nexe. The module is now running as a real
// Native Client executable in a NaCl sandbox, with nacl-gdb attached.
// *** RUN YOUR MODULE IN THE WILD ***
// You can run your nexe outside of Visual Studio, directly from Chrome by
// following these steps:
// - Build STEP6 and verify the file
// <project directory>/NaCl64/newlib/Debug/hello_nacl_64.nexe exists
// - Copy the folder <project directory> into your NaCl SDK's example
// directory.
// - Go to the NaCl SDK directory and launch the httpd.py server.
// - Launch Chrome, go to about:flags and enable the Native Client flag and
// relaunch Chrome
// - Point Chrome at http://localhost:5103/hello_nacl
#ifdef STEP6
// remove Windows-dependent code.
#undef STEP1
#undef STEP3
#undef STEP4
#define NULL 0
#else
// includes for Windows APIs.
#include <windows.h>
#include <stdlib.h>
#include <tchar.h>
#endif
#ifdef STEP2
// includes for PPAPI
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_module.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb.h"
#include "ppapi/c/ppb_instance.h"
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/c/ppb_var.h"
#include "ppapi/c/ppb_core.h"
#include "ppapi/c/ppp.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/ppp_messaging.h"
#include <string.h>
// Native Client APIs
static PPB_Messaging* ppb_messaging_interface = NULL;
static PPB_Var* ppb_var_interface = NULL;
static PPB_Core* ppb_core_interface = NULL;
PP_Instance myInstance;
int InitInstanceInPCWindow();
void InitInstanceInBrowserWindow();
#endif
#ifdef STEP4
// Implements message handling in a callback function.
void HelloWorldCallbackFun(void* user_data, int32_t result);
struct PP_CompletionCallback HelloWorldCallback = {
HelloWorldCallbackFun, NULL };
void HelloWorldCallbackFun(void* user_data, int32_t result) {
MSG uMsg;
if (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&uMsg);
DispatchMessage(&uMsg);
}
ppb_core_interface->CallOnMainThread(100, HelloWorldCallback, 0);
}
#endif
#ifdef STEP2
// The basic framework needed for all Native Client Modules. Handles creation
// of the module instance and initial handshake with the browser.
/**
* Creates new string PP_Var from C string. Useful utility for
* message-handling.
*/
static struct PP_Var CStrToVar(const char* str) { if (ppb_var_interface !=
NULL) { return ppb_var_interface->VarFromUtf8(str, strlen(str)); } return
PP_MakeUndefined(); }
void InitInstanceInBrowserWindow() {
// Pass the text to the browser page, there is no separate app window
// anymore. The text is added as a new element to the page, it does not
// appear in the module's embed view.
ppb_messaging_interface->PostMessage(myInstance,
CStrToVar("Hello, Native Client!"));
}
/**
* Called when the NaCl module is instantiated on the web page.
*/
static PP_Bool Instance_DidCreate(PP_Instance instance,
uint32_t argc,
const char* argn[],
const char* argv[]) {
myInstance = instance;
ppb_messaging_interface->PostMessage(instance,
CStrToVar("Start Instance_DidCreate"));
#ifdef STEP5
// Will be included in STEP5 and STEP6
// Uses messaging to relay text to the module's view on the web page
InitInstanceInBrowserWindow();
#else
#ifdef STEP3
// Will be included in STEP3 and STEP4 only
// Uses WndProc to place text in a window separate from the browser.
InitInstanceInPCWindow();
#endif
#endif
ppb_messaging_interface->PostMessage(instance,
CStrToVar("End Instance_DidCreate"));
return PP_TRUE;
}
/**
* Called when the NaCl module is destroyed.
*/
static void Instance_DidDestroy(PP_Instance instance) {
}
/**
* Called when the position, the size, or the clip rect of the element in the
* browser that corresponds to this NaCl module has changed.
*/
static void Instance_DidChangeView(PP_Instance instance,
PP_Resource view_resource) {
}
/**
* Notification that the given NaCl module has gained or lost focus.
*/
static void Instance_DidChangeFocus(PP_Instance instance,
PP_Bool has_focus) {
}
/**
* Handler that gets called after a full-frame module is instantiated based on
* registered MIME types. This function is not called on NaCl modules. This
* function is essentially a place-holder for the required function pointer in
* the PPP_Instance structure.
*/
static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance,
PP_Resource url_loader) {
/* NaCl modules do not need to handle the document load function. */
return PP_FALSE;
}
/**
* Entry points for the module.
* Initialize needed interfaces: PPB_Core, PPB_Messaging and PPB_Var.
*/
PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id,
PPB_GetInterface get_browser) {
ppb_messaging_interface = (PPB_Messaging*)
get_browser(PPB_MESSAGING_INTERFACE);
ppb_var_interface = (PPB_Var*)get_browser(PPB_VAR_INTERFACE);
ppb_core_interface = (PPB_Core*)get_browser(PPB_CORE_INTERFACE);
return PP_OK;
}
/**
* Returns an interface pointer for the interface of the given name, or NULL
* if the interface is not supported.
*/
PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) {
static PPP_In
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
之前由于部分同学看我博客:https://mp.csdn.net/postedit/72821974,然后下载资源https://download.csdn.net/download/y601500359/9856804,说是编译不过,其实不是资源有问题,是同学们没有安装相应的环境,这我精简了部分环境,有需要的可以下载。
资源推荐
资源详情
资源评论
收起资源包目录
naclsdk_vs_addin (128个子文件)
NativeClientVSAddIn.AddIn 884B
NativeClientVSAddIn.AddIn 884B
all-wcprops 711B
all-wcprops 701B
all-wcprops 691B
all-wcprops 595B
all-wcprops 588B
all-wcprops 581B
all-wcprops 148B
all-wcprops 147B
all-wcprops 146B
install.bat 72B
hello_nacl.c 12KB
hello_world.cc 19KB
hello_nacl_cpp.cc 10KB
matrix.cc 4KB
README.chromium 549B
NativeClientVSAddIn.dll 45KB
NativeClientVSAddIn.dll 45KB
NaCl.Build.CPPTasks.dll 41KB
entries 839B
entries 835B
entries 831B
entries 662B
entries 659B
entries 656B
entries 306B
entries 305B
entries 304B
fragment_shader_es2.frag 239B
matrix.h 1KB
index.html 1KB
index.html 1KB
index_newlib.html 703B
index_pnacl.html 702B
index_glibc.html 702B
index_win.html 700B
common.js 7KB
LICENSE 2KB
Microsoft.Cpp.Win32.targets.patch 3KB
ppapi_general.xml.patch 3KB
Microsoft.Cpp.Win32.v100.props.patch 2KB
Toolset.props.patch 2KB
Microsoft.Cpp.Win32.default.props.patch 1KB
Microsoft.Cpp.Win32.props.patch 1KB
Microsoft.Cpp.Win32.v100.targets.patch 991B
Platform.default.props.patch 851B
Toolset.targets.patch 748B
ppapi_general_ps.xml.patch 202B
Platform.targets.patch 90B
NaCl.Toolset.default.props 5KB
NaCl.Paths.default.props 3KB
PPAPI.override.props 2KB
Microsoft.Cpp.PNaCl.default.props 2KB
Microsoft.Cpp.NaCLARM.default.props 2KB
Microsoft.Cpp.PNaCl.props 2KB
Microsoft.Cpp.NaCl32.props 2KB
Microsoft.Cpp.NaClARM.props 2KB
Microsoft.Cpp.NaCl64.props 2KB
Microsoft.Cpp.NaCL32.default.props 2KB
Microsoft.Cpp.NaCl64.default.props 2KB
NaCl.override.props 1KB
Microsoft.Cpp.PNaCl.v110.props 151B
Microsoft.Cpp.NaCl32.v110.props 151B
Microsoft.Cpp.NaClARM.v110.props 151B
Microsoft.Cpp.NaCl64.v110.props 151B
Microsoft.Cpp.NaCl.win_x86_glibc.props 85B
Microsoft.Cpp.NaCl.win_x86_newlib.props 85B
ElementTree.py 55KB
install.py 12KB
ElementPath.py 9KB
create_ppapi_platform.py 8KB
xml_patch.py 6KB
ElementInclude.py 5KB
compiler_wrapper.py 4KB
__init__.py 2KB
__init__.py 611B
cElementTree.py 62B
ElementTree.pyc 36KB
create_ppapi_platform.pyc 9KB
ElementPath.pyc 8KB
xml_patch.pyc 5KB
__init__.pyc 713B
__init__.pyc 145B
hello.raw 48KB
hello_nacl_cpp.sln 2KB
hello_nacl.sln 2KB
hello_world_gles.sln 2KB
Microsoft.Cpp.PNaCl.targets.svn-base 7KB
Microsoft.Cpp.NaCl32.targets.svn-base 7KB
Microsoft.Cpp.NaClARM.targets.svn-base 7KB
Microsoft.Cpp.PNaCl.props.svn-base 2KB
Microsoft.Cpp.NaCl32.props.svn-base 2KB
Microsoft.Cpp.NaClARM.props.svn-base 2KB
Microsoft.Cpp.PNaCl.default.props.svn-base 2KB
Microsoft.Cpp.NaCl32.default.props.svn-base 2KB
Microsoft.Cpp.NaClARM.default.props.svn-base 2KB
Microsoft.Cpp.PNaCl.v110.props.svn-base 151B
Microsoft.Cpp.NaCl32.v110.props.svn-base 151B
Microsoft.Cpp.NaClARM.v110.props.svn-base 151B
共 128 条
- 1
- 2
SunkingYang
- 粉丝: 1w+
- 资源: 57
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页