我想在CEF里使用PPAPI,CEF使用VS 2013 Update 4編譯。因此我嘗試了使用VS 2013來編譯PPAPI插件。
PPAPI的代碼在這里:[https://chromium.googlesource.com/chromium/src/ppapi/](https://chromium.googlesource.com/chromium/src/ppapi/),可以用下列命令check出來:
~~~
git clone https://chromium.googlesource.com/chromium/src/ppapi
~~~
也可以下載master分支的tgz包。
# VS工程
新建一個Win32項目,類型選DLL,去掉預編譯頭文件stdafx.h和stdafx.cpp,并且在項目屬性–>配置屬性–>C/C++–>預編譯頭,把預編譯頭選項的值設置為不使用預編譯頭。
復制ppapi/examples/stub/stub.c文件到項目文件夾下,并添加到項目里。做簡單修改,打印點兒調試信息。stub.c內容如下:
~~~
// Copyright (c) 2010 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 is the simplest possible C Pepper plugin that does nothing. If you're
// using C++, you will want to look at stub.cc which uses the more convenient
// C++ wrappers.
#include <stddef.h>
#include <stdint.h>
#include <Windows.h>
#include <tchar.h>
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_module.h"
#include "ppapi/c/ppb.h"
#include "ppapi/c/ppp.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/ppp_instance.h"
PP_Module g_module_id;
PPB_GetInterface g_get_browser_interface = NULL;
PP_EXPORT int32_t PPP_InitializeModule(PP_Module module_id,
PPB_GetInterface get_browser_interface) {
// Save the global module information for later.
g_module_id = module_id;
g_get_browser_interface = get_browser_interface;
OutputDebugString(_T("PPP_InitializeModule was called\r\n"));
return PP_OK;
}
PP_EXPORT void PPP_ShutdownModule() {
OutputDebugString(_T("PPP_ShutdownModule was called\r\n"));
}
PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
// You will normally implement a getter for at least PPP_INSTANCE_INTERFACE
// here.
OutputDebugString(_T("PPP_GetInterface was called\r\n"));
return NULL;
}
~~~
# PPAPI plugin
參考[https://code.google.com/p/ppapi/wiki/GettingStarted](https://code.google.com/p/ppapi/wiki/GettingStarted),C語言版的PPAPI plugin,必須實現下列函數:
- PPP_InitializeModule,插件加載時會被調用,返回0表示成功
- PPP_ShutdownModule,插件卸載時會被調用
- PPP_GetInterface,瀏覽器創建插件實例時會被調用
這些函數在ppp.h中定義。實現這些函數時,使用PP_EXPORT宏修飾一下即可。
一個DLL,實現了上述三個函數,就可以做為PPAPI插件來用了,不過只是樣子貨,只能看到被加載、創建,干不了什么實際的事兒,是個PPAPI 版本的Hello World。
后面我們會改造stub,顯示點東西出來。
相關文章參考:
- [**CEF Windows開發環境搭建**](http://blog.csdn.net/foruok/article/details/50468642)
- [**CEF加載PPAPI插件**](http://blog.csdn.net/foruok/article/details/50485448)
- 前言
- CEF Windows開發環境搭建
- CEF加載PPAPI插件
- VS2013編譯最簡單的PPAPI插件
- 理解PPAPI的設計
- PPAPI插件與瀏覽器的交互過程
- Windows下從源碼編譯CEF
- 編譯PPAPI的media_stream_video示例
- PPAPI插件的繪圖與輸入事件處理
- 在PPAPI插件中創建本地窗口
- PPAPI插件與瀏覽器的通信
- Windows下從源碼編譯Skia
- 在PPAPI插件中使用Skia繪圖
- 加載DLL中的圖片資源生成Skia中的SkBitmap對象
- PPAPI+Skia實現的涂鴉板
- PPAPI中使用Chromium的3D圖形接口
- PPAPI中使用OpenGL ES繪圖