diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 21:10:23 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-06 21:10:23 +0000 |
commit | 0033cc6fe696a94e6fcaafe4ba5d3d1fcb4421cb (patch) | |
tree | e77ca1f18ec9e64a9e3f5a6c377f2eebb33372dc /webkit | |
parent | 1dcd5e8c3061bcd016dd99a04b939ba23e60497f (diff) | |
download | chromium_src-0033cc6fe696a94e6fcaafe4ba5d3d1fcb4421cb.zip chromium_src-0033cc6fe696a94e6fcaafe4ba5d3d1fcb4421cb.tar.gz chromium_src-0033cc6fe696a94e6fcaafe4ba5d3d1fcb4421cb.tar.bz2 |
Make Pepper plugins work on Linux.
- fix pepper_test_plugin so that it is loaded on Linux
- remove skia & base dependency in test plugin so that it can be compiled with -fPIC
- remove ifdef WIN in pepper code
Patch by neb@chromium.org
Original review: http://codereview.chromium.org/501124/show
BUG=none
TEST=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/tools/pepper_test_plugin/event_handler.cc | 53 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/main.cc | 50 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp | 14 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.cc | 44 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.h | 10 |
5 files changed, 104 insertions, 67 deletions
diff --git a/webkit/tools/pepper_test_plugin/event_handler.cc b/webkit/tools/pepper_test_plugin/event_handler.cc index 7884fac..65df790 100644 --- a/webkit/tools/pepper_test_plugin/event_handler.cc +++ b/webkit/tools/pepper_test_plugin/event_handler.cc @@ -26,11 +26,8 @@ #include "webkit/tools/pepper_test_plugin/event_handler.h" #include <stdio.h> -#include <string> +#include <sstream> -#include "base/basictypes.h" -#include "base/logging.h" -#include "base/string_util.h" #include "webkit/tools/pepper_test_plugin/plugin_object.h" EventHandler* event_handler = NULL; @@ -58,7 +55,10 @@ void EventHandler::addText(const char* cstr) { } std::string EventHandler::EventName(double timestamp, int32 type) { - std::string str = DoubleToString(timestamp) + ": "; + std::stringstream strstr; + strstr.setf(std::ios::fixed, std::ios::floatfield); + strstr << timestamp << ": "; + std::string str(strstr.str()); switch (type) { case NPEventType_MouseDown: return str + "MouseDown"; @@ -94,46 +94,43 @@ std::string EventHandler::EventName(double timestamp, int32 type) { int EventHandler::handle(void* event) { NPPepperEvent* npevent = reinterpret_cast<NPPepperEvent*>(event); - std::string str = EventName(npevent->timeStampSeconds, npevent->type); + std::stringstream str; + str << EventName(npevent->timeStampSeconds, npevent->type); switch (npevent->type) { case NPEventType_MouseDown: case NPEventType_MouseUp: case NPEventType_MouseMove: case NPEventType_MouseEnter: case NPEventType_MouseLeave: - str += StringPrintf(": mod %x, but: %x, x: %d, y: %d, click: %d", - npevent->u.mouse.modifier, - npevent->u.mouse.button, - npevent->u.mouse.x, - npevent->u.mouse.y, - npevent->u.mouse.clickCount); + str << ": mod " << npevent->u.mouse.modifier + << ", but: " << npevent->u.mouse.button + << ", x: " << npevent->u.mouse.x + << ", y: " << npevent->u.mouse.y + << ", click: " << npevent->u.mouse.clickCount; break; case NPEventType_MouseWheel: - str += StringPrintf(": mod %x, dx: %f, dy: %f, wtx: %f, wty: %d: sbp %d", - npevent->u.wheel.modifier, - npevent->u.wheel.deltaX, - npevent->u.wheel.deltaY, - npevent->u.wheel.wheelTicksX, - npevent->u.wheel.wheelTicksY, - npevent->u.wheel.scrollByPage); + str << ": mod " << npevent->u.wheel.modifier + << ", dx: " << npevent->u.wheel.deltaX + << ", dy: " << npevent->u.wheel.deltaY + << ", wtx: " << npevent->u.wheel.wheelTicksX + << ", wty: " << npevent->u.wheel.wheelTicksY + << ", sbp:" << npevent->u.wheel.scrollByPage; break; case NPEventType_RawKeyDown: case NPEventType_KeyDown: case NPEventType_KeyUp: - str += StringPrintf(": mod %x, key: %x", - npevent->u.key.modifier, - npevent->u.key.normalizedKeyCode); + str << ": mod " << npevent->u.key.modifier + << ", key: " << npevent->u.key.normalizedKeyCode; break; case NPEventType_Char: - str += StringPrintf(": mod %x, text: ", - npevent->u.character.modifier); + str << ": mod " << npevent->u.character.modifier << ", text: "; size_t i; for (i = 0; i < arraysize(npevent->u.character.text); ++i) { - str += StringPrintf("%x ", npevent->u.character.text[i]); + str << npevent->u.character.text[i] << ' '; } - str += ", unmod: "; + str << ", unmod: "; for (i = 0; i < arraysize(npevent->u.character.unmodifiedText); ++i) { - str += StringPrintf("%x ", npevent->u.character.unmodifiedText[i]); + str << npevent->u.character.unmodifiedText[i] << ' '; } break; case NPEventType_Minimize: @@ -144,7 +141,7 @@ int EventHandler::handle(void* event) { default: break; } - addText(str.c_str()); + addText(str.str().c_str()); return 0; } diff --git a/webkit/tools/pepper_test_plugin/main.cc b/webkit/tools/pepper_test_plugin/main.cc index ef9a64b..8e46ecd 100644 --- a/webkit/tools/pepper_test_plugin/main.cc +++ b/webkit/tools/pepper_test_plugin/main.cc @@ -34,15 +34,21 @@ #include <stdlib.h> #include <stdio.h> +#if defined(INDEPENDENT_PLUGIN) +#include <iostream> +#define LOG(x) std::cerr +#else #include "base/logging.h" #include "base/string_util.h" +#endif +#include "webkit/glue/plugins/nphostapi.h" #include "webkit/tools/pepper_test_plugin/plugin_object.h" #include "webkit/tools/pepper_test_plugin/event_handler.h" -#ifdef WIN32 -#define NPAPI WINAPI -#else -#define NPAPI +#if __GNUC__ >= 4 +#define EXPORT __attribute__ ((visibility("default"))) +#elif defined(_MSC_VER) +#define EXPORT __declspec(dllexport) #endif namespace { @@ -51,7 +57,14 @@ void Log(NPP instance, const char* format, ...) { va_list args; va_start(args, format); std::string message("PLUGIN: "); +#if defined(INDEPENDENT_PLUGIN) + { + char msgbuf[100]; + vsnprintf(msgbuf, 100, format, args); + } +#else StringAppendV(&message, format, args); +#endif va_end(args); NPObject* window_object = 0; @@ -99,34 +112,25 @@ void Log(NPP instance, const char* format, ...) { // Plugin entry points extern "C" { -#if defined(OS_WIN) -//__declspec(dllexport) -#endif -NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs +EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* browser_funcs #if defined(OS_LINUX) , NPPluginFuncs* plugin_funcs #endif ); -#if defined(OS_WIN) -//__declspec(dllexport) -#endif -NPError NPAPI NP_GetEntryPoints(NPPluginFuncs* plugin_funcs); +EXPORT NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* plugin_funcs); -#if defined(OS_WIN) -//__declspec(dllexport) -#endif -void NPAPI NP_Shutdown() { +EXPORT void API_CALL NP_Shutdown() { } #if defined(OS_LINUX) -NPError NP_GetValue(NPP instance, NPPVariable variable, void* value); -const char* NP_GetMIMEDescription(); +EXPORT NPError API_CALL NP_GetValue(NPP instance, NPPVariable variable, void* value); +EXPORT const char* API_CALL NP_GetMIMEDescription(); #endif } // extern "C" // Plugin entry points -NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs +EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* browser_funcs #if defined(OS_LINUX) , NPPluginFuncs* plugin_funcs #endif @@ -141,7 +145,7 @@ NPError NPAPI NP_Initialize(NPNetscapeFuncs* browser_funcs // Entrypoints ----------------------------------------------------------------- -NPError NPAPI NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) { +NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) { plugin_funcs->version = 11; plugin_funcs->size = sizeof(plugin_funcs); plugin_funcs->newp = NPP_New; @@ -271,11 +275,11 @@ NPError NPP_SetValue(NPP instance, NPNVariable variable, void* value) { } #if defined(OS_LINUX) -NPError NP_GetValue(NPP instance, NPPVariable variable, void* value) { +NPError API_CALL NP_GetValue(NPP instance, NPPVariable variable, void* value) { return NPP_GetValue(instance, variable, value); } -const char* NP_GetMIMEDescription() { - return "pepper-application/x-pepper-test-plugin pepper test;"; +const char* API_CALL NP_GetMIMEDescription() { + return "pepper-application/x-pepper-test-plugin::Pepper Test"; } #endif diff --git a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp index aa3908a..9383747 100644 --- a/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp +++ b/webkit/tools/pepper_test_plugin/pepper_test_plugin.gyp @@ -5,8 +5,6 @@ 'target_name': 'pepper_test_plugin', 'type': 'shared_library', 'dependencies': [ - '../../../base/base.gyp:base', - '../../../skia/skia.gyp:skia', '../../../third_party/npapi/npapi.gyp:npapi', ], 'include_dirs': [ @@ -23,7 +21,17 @@ 'pepper_test_plugin.def', 'pepper_test_plugin.rc', ], - }] + }], + ['OS=="linux" and (target_arch=="x64" or target_arch=="arm")', { + # Shared libraries need -fPIC on x86-64 + 'cflags': ['-fPIC'], + 'defines': ['INDEPENDENT_PLUGIN'], + }, { + 'dependencies': [ + '../../../base/base.gyp:base', + '../../../skia/skia.gyp:skia', + ], + }], ], 'sources': [ 'command_buffer_pepper.cc', diff --git a/webkit/tools/pepper_test_plugin/plugin_object.cc b/webkit/tools/pepper_test_plugin/plugin_object.cc index 59212ac..91b406f 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.cc +++ b/webkit/tools/pepper_test_plugin/plugin_object.cc @@ -28,12 +28,16 @@ #include <stdio.h> #include <string> +#if defined(INDEPENDENT_PLUGIN) +#define CHECK(x) +#else #include "base/logging.h" #include "gpu/command_buffer/client/gles2_lib.h" #include "gpu/command_buffer/client/gles2_demo_cc.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/effects/SkGradientShader.h" +#endif #include "webkit/tools/pepper_test_plugin/event_handler.h" #include "webkit/tools/pepper_test_plugin/test_object.h" @@ -210,7 +214,26 @@ NPClass plugin_class = { // Bitmap painting ------------------------------------------------------------- -void DrawSampleBitmap(SkCanvas& canvas, int width, int height) { +#if defined(INDEPENDENT_PLUGIN) +void DrawSampleBitmap(void *region, int width, int height) { + int32 *bitmap = reinterpret_cast<int32 *>(region); + + for (int h = 0; h < height; ++h) { + uint8 opacity = (h * 0xff) / height; + for (int w = 0; w < width; ++w) { + // kudos to apatrick for noticing we're using premultiplied alpha + uint8 greenness = (w * opacity) / width; + *bitmap++ = (opacity << 24) | (greenness << 8); + } + } +} +#else +void DrawSampleBitmap(void *region, int width, int height) { + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); + bitmap.setPixels(region); + + SkCanvas canvas(bitmap); SkRect rect; rect.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(width), SkIntToScalar(height)); @@ -233,7 +256,7 @@ void DrawSampleBitmap(SkCanvas& canvas, int width, int height) { canvas.drawPath(path, paint); } - +#endif void FlushCallback(NPP instance, NPDeviceContext* context, NPError err, void* user_data) { } @@ -290,19 +313,14 @@ void PluginObject::New(NPMIMEType pluginType, void PluginObject::SetWindow(const NPWindow& window) { if (dimensions_ == 2) { - size_.set_width(window.width); - size_.set_height(window.height); + width_ = window.width; + height_ = window.height; NPDeviceContext2DConfig config; NPDeviceContext2D context; device2d_->initializeContext(npp_, &config, &context); - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); - bitmap.setPixels(context.region); - - SkCanvas canvas(bitmap); - DrawSampleBitmap(canvas, window.width, window.height); + DrawSampleBitmap(context.region, width_, height_); // TODO(brettw) figure out why this cast is necessary, the functions seem to // match. Could be a calling convention mismatch? @@ -310,6 +328,7 @@ void PluginObject::SetWindow(const NPWindow& window) { reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); device2d_->flushContext(npp_, &context, callback, NULL); } else { +#if !defined(INDEPENDENT_PLUGIN) if (!command_buffer_.get()) { if (!InitializeCommandBuffer()) return; @@ -319,10 +338,12 @@ void PluginObject::SetWindow(const NPWindow& window) { // Schedule the first call to Draw. browser->pluginthreadasynccall(npp_, Draw3DCallback, this); +#endif } } void PluginObject::Draw3D() { +#if !defined(INDEPENDENT_PLUGIN) // Render some stuff. gles2::g_gl_impl = gles2_implementation_.get(); GLFromCPPTestFunction(); @@ -332,9 +353,11 @@ void PluginObject::Draw3D() { // Schedule another call to Draw. browser->pluginthreadasynccall(npp_, Draw3DCallback, this); +#endif } bool PluginObject::InitializeCommandBuffer() { +#if !defined(INDEPENDENT_PLUGIN) const static int32 kCommandBufferSize = 512 * 1024; command_buffer_.reset(new CommandBufferPepper(npp_, browser)); if (command_buffer_->Initialize(kCommandBufferSize)) { @@ -360,6 +383,7 @@ bool PluginObject::InitializeCommandBuffer() { } command_buffer_.reset(); +#endif return false; } diff --git a/webkit/tools/pepper_test_plugin/plugin_object.h b/webkit/tools/pepper_test_plugin/plugin_object.h index 4dcff15..e671a94 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.h +++ b/webkit/tools/pepper_test_plugin/plugin_object.h @@ -27,11 +27,12 @@ #define WEBKIT_TOOLS_PEPPER_TEST_PLUGIN_PLUGIN_OBJECT_H_ #include "base/basictypes.h" -#include "base/gfx/size.h" #include "base/scoped_ptr.h" +#include "webkit/glue/plugins/nphostapi.h" +#if !defined(INDEPENDENT_PLUGIN) #include "gpu/command_buffer/client/gles2_implementation.h" #include "webkit/tools/pepper_test_plugin/command_buffer_pepper.h" -#include "webkit/glue/plugins/nphostapi.h" +#endif extern NPNetscapeFuncs* browser; @@ -61,11 +62,14 @@ class PluginObject { // TODO(apatrick): this destruction order causes the plugin to crash on // shutdown. +#if !defined(INDEPENDENT_PLUGIN) scoped_ptr<CommandBufferPepper> command_buffer_; scoped_ptr<gpu::gles2::GLES2Implementation> gles2_implementation_; scoped_ptr<gpu::gles2::GLES2CmdHelper> helper_; +#endif - gfx::Size size_; + int width_; + int height_; DISALLOW_COPY_AND_ASSIGN(PluginObject); }; |