diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-01 23:07:02 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-01 23:07:02 +0000 |
commit | 66b4e8dfc5cce75c998889d5b968ecb72a204447 (patch) | |
tree | 215d020b5bb8a5cfa43debf580e9bd3d55091b77 /webkit | |
parent | 3984b4b1edee2b14b0ebd41d31fc9fedfc7a0ef9 (diff) | |
download | chromium_src-66b4e8dfc5cce75c998889d5b968ecb72a204447.zip chromium_src-66b4e8dfc5cce75c998889d5b968ecb72a204447.tar.gz chromium_src-66b4e8dfc5cce75c998889d5b968ecb72a204447.tar.bz2 |
Update the Pepper APIs to the latest spec for the 2D demo plugin.
This also adds the npapi headers to the npapi.gyp file since I got tired of
Visual Studio not finding the files.
This removes the "open file in sandbox" feature which it doesn't look like we
will use.
One more significant change is that I changed to including pepper.h in all
cases, even when pepper is disabled. We used to have a forward declare in
npapi.h for the structs in question, but we'll be adding a lot more structs for
the different contexts and I don't think this will scale. I think its OK fo
rthe pepper API declarations to be available when Pepper isn't enabled.
BUT=none
TEST=none
Review URL: http://codereview.chromium.org/453015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33501 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/pepper/pepper.h | 179 | ||||
-rw-r--r-- | webkit/glue/plugins/nphostapi.h | 2 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_host.cc | 127 | ||||
-rw-r--r-- | webkit/glue/webplugin_delegate.h | 36 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.cc | 45 | ||||
-rw-r--r-- | webkit/tools/pepper_test_plugin/plugin_object.h | 2 |
6 files changed, 140 insertions, 251 deletions
diff --git a/webkit/glue/pepper/pepper.h b/webkit/glue/pepper/pepper.h deleted file mode 100644 index 269cea8..0000000 --- a/webkit/glue/pepper/pepper.h +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) 2006-2009 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. - -#ifndef WEBKIT_GLUE_PEPPER_PEPPER_H_ -#define WEBKIT_GLUE_PEPPER_PEPPER_H_ - -#ifdef PEPPER_APIS_ENABLED - -#include "base/basictypes.h" -#include "third_party/npapi/bindings/npapi.h" - -/* - * A fake "enum" value for getting Pepper extensions. - * The variable returns a pointer to an NPPepperExtensions structure - */ -#define NPNVPepperExtensions ((NPNVariable) 4000) - -typedef enum { - NPMouseButton_None = -1, - NPMouseButton_Left = 0, - NPMouseButton_Middle = 1, - NPMouseButton_Right = 2, -} NPMouseButtons; - -typedef enum { - NPEventType_Undefined = -1, - NPEventType_MouseDown = 0, - NPEventType_MouseUp = 1, - NPEventType_MouseMove = 2, - NPEventType_MouseEnter = 3, - NPEventType_MouseLeave = 4, - NPEventType_MouseWheel = 5, - NPEventType_RawKeyDown = 6, - NPEventType_KeyDown = 7, - NPEventType_KeyUp = 8, - NPEventType_Char = 9, - NPEventType_Minimize = 10, - NPEventType_Focus = 11, - NPEventType_Device = 12 -} NPEventTypes; - -typedef enum { - NPEventModifier_ShiftKey = 1 << 0, - NPEventModifier_ControlKey = 1 << 1, - NPEventModifier_AltKey = 1 << 2, - NPEventModifier_MetaKey = 1 << 3, - NPEventModifier_IsKeyPad = 1 << 4, - NPEventModifier_IsAutoRepeat = 1 << 5, - NPEventModifier_LeftButtonDown = 1 << 6, - NPEventModifier_MiddleButtonDown = 1 << 7, - NPEventModifier_RightButtonDown = 1 << 8 -} NPEventModifiers; - -typedef struct _NPKeyEvent -{ - uint32 modifier; - uint32 normalizedKeyCode; -} NPKeyEvent; - -typedef struct _NPCharacterEvent -{ - uint32 modifier; - uint16 text[4]; - uint16 unmodifiedText[4]; -} NPCharacterEvent; - -typedef struct _NPMouseEvent -{ - uint32 modifier; - int32 button; - int32 x; - int32 y; - int32 clickCount; -} NPMouseEvent; - -typedef struct _NPMouseWheelEvent -{ - uint32 modifier; - float deltaX; - float deltaY; - float wheelTicksX; - float wheelTicksY; - uint32 scrollByPage; -} NPMouseWheelEvent; - -typedef struct _NPDeviceEvent { - uint32 device_uid; - uint32 subtype; - /* uint8 generic[0]; */ -} NPDeviceEvent; - -typedef struct _NPMinimizeEvent { - int32 value; -} NPMinimizeEvent; - -typedef struct _NPFocusEvent { - int32 value; -} NPFocusEvent; - -typedef struct _NPPepprEvent -{ - uint32 size; - int32 type; - double timeStampSeconds; - union { - NPKeyEvent key; - NPCharacterEvent character; - NPMouseEvent mouse; - NPMouseWheelEvent wheel; - NPMinimizeEvent minimize; - NPFocusEvent focus; - NPDeviceEvent device; - } u; -} NPPepperEvent; - -typedef struct _NPPepperRegion -{ - int32 x; - int32 y; - int32 w; - int32 h; -} NPPepperRegion; - -typedef enum _NPRenderType -{ - NPRenderGraphicsRGBA -} NPRenderType; - -typedef struct _NPRenderContext -{ - union { - struct { - void* region; - int32 stride; - - // The dirty region that the plugin has painted into the buffer. This - // will be initialized to the size of the plugin image in - // initializeRenderContextPtr. The plugin can change the values to only - // update portions of the image. - struct { - int32 left; - int32 top; - int32 right; - int32 bottom; - } dirty; - } graphicsRgba; - } u; -} NPRenderContext; - -typedef void (*NPFlushRenderContextCallbackPtr)(NPRenderContext* context, - NPError err, - void* userData); -typedef NPError (*NPInitializeRenderContextPtr)(NPP instance, - NPRenderType type, - NPRenderContext* context); -typedef NPError (*NPFlushRenderContextPtr)(NPP instance, - NPRenderContext* context, - NPFlushRenderContextCallbackPtr callback, - void* userData); -typedef NPError (*NPDestroyRenderContextPtr)(NPP instance, - NPRenderContext* context); -typedef NPError (*NPOpenFilePtr)(NPP instance, const char* fileName, void** handle); - -typedef struct _NPPepperExtensions -{ - /* Renderer extensions */ - NPInitializeRenderContextPtr initializeRender; - NPFlushRenderContextPtr flushRender; - NPDestroyRenderContextPtr destroyRender; - /* Shared memory extensions */ - - /* I/O extensions */ - NPOpenFilePtr openFile; -} NPPepperExtensions; - -#endif /* PEPPER_APIS_ENABLED */ - -#endif /* WEBKIT_GLUE_PEPPER_PEPPER_H_ */ diff --git a/webkit/glue/plugins/nphostapi.h b/webkit/glue/plugins/nphostapi.h index f840954..53c684c 100644 --- a/webkit/glue/plugins/nphostapi.h +++ b/webkit/glue/plugins/nphostapi.h @@ -8,8 +8,8 @@ #define WEBKIT_GLUE_PLUGIN_NPHOSTAPI_H__ #include "base/port.h" -#include "webkit/glue/pepper/pepper.h" #include "third_party/npapi/bindings/npapi.h" +#include "third_party/npapi/bindings/npapi_extensions.h" #include "third_party/npapi/bindings/npruntime.h" #ifdef __cplusplus diff --git a/webkit/glue/plugins/plugin_host.cc b/webkit/glue/plugins/plugin_host.cc index 7abe811..8cc094f 100644 --- a/webkit/glue/plugins/plugin_host.cc +++ b/webkit/glue/plugins/plugin_host.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -20,11 +20,11 @@ #include "webkit/glue/webplugininfo.h" #include "webkit/glue/webplugin_delegate.h" #include "webkit/glue/webkit_glue.h" -#include "webkit/glue/pepper/pepper.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/plugins/plugin_lib.h" #include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/plugins/plugin_stream_url.h" +#include "third_party/npapi/bindings/npapi_extensions.h" #include "third_party/npapi/bindings/npruntime.h" using WebKit::WebBindings; @@ -666,31 +666,81 @@ void NPN_ForceRedraw(NPP id) { } #if defined(PEPPER_APIS_ENABLED) -static NPError InitializeRenderContext(NPP id, - NPRenderType type, - NPRenderContext* context) { +// Pepper 2D device API -------------------------------------------------------- + +static NPError Device2DQueryCapability(NPP id, int32 capability, int32* value) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + plugin->webplugin()->delegate()->Device2DQueryCapability(capability, value); + return NPERR_NO_ERROR; + } else { + return NPERR_GENERIC_ERROR; + } +} + +static NPError Device2DQueryConfig(NPP id, + const NPDeviceConfig* request, + NPDeviceConfig* obtain) { scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); if (plugin) { - webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); - // Set up the renderer for the specified type. - return delegate->InitializeRenderContext(type, context); + return plugin->webplugin()->delegate()->Device2DQueryConfig( + static_cast<const NPDeviceContext2DConfig*>(request), + static_cast<NPDeviceContext2DConfig*>(obtain)); } return NPERR_GENERIC_ERROR; } -static NPError FlushRenderContext(NPP id, - NPRenderContext* context, - NPFlushRenderContextCallbackPtr callback, - void* user_data) { +static NPError Device2DInitializeContext(NPP id, + const NPDeviceConfig* config, + NPDeviceContext* context) { scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); if (plugin) { - webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); - // Do the flush. - NPError err = delegate->FlushRenderContext(context); + return plugin->webplugin()->delegate()->Device2DInitializeContext( + static_cast<const NPDeviceContext2DConfig*>(config), + static_cast<NPDeviceContext2D*>(context)); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DSetStateContext(NPP id, + NPDeviceContext* context, + int32 state, + int32 value) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device2DSetStateContext( + static_cast<NPDeviceContext2D*>(context), state, value); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DGetStateContext(NPP id, + NPDeviceContext* context, + int32 state, + int32* value) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + return plugin->webplugin()->delegate()->Device2DGetStateContext( + static_cast<NPDeviceContext2D*>(context), state, value); + } + return NPERR_GENERIC_ERROR; +} + +static NPError Device2DFlushContext(NPP id, + NPDeviceContext* context, + NPDeviceFlushContextCallbackPtr callback, + void* user_data) { + scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); + if (plugin) { + NPError err = plugin->webplugin()->delegate()->Device2DFlushContext( + static_cast<NPDeviceContext2D*>(context), callback, user_data); // Invoke the callback to inform the caller the work was done. + // TODO(brettw) this is probably not how we want this to work, this should + // happen when the frame is painted so the plugin knows when it can draw + // the next frame. if (callback != NULL) - (*callback)(context, err, user_data); + (*callback)(id, context, err, user_data); // Return any errors. return err; @@ -698,23 +748,36 @@ static NPError FlushRenderContext(NPP id, return NPERR_GENERIC_ERROR; } -static NPError DestroyRenderContext(NPP id, - NPRenderContext* context) { +static NPError Device2DDestroyContext(NPP id, + NPDeviceContext* context) { scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); if (plugin) { - webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); - return delegate->DestroyRenderContext(context); + return plugin->webplugin()->delegate()->Device2DDestroyContext( + static_cast<NPDeviceContext2D*>(context)); } return NPERR_GENERIC_ERROR; } -static NPError OpenFileInSandbox(NPP id, const char* file_name, void** handle) { - scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id); - if (!plugin) - return NPERR_GENERIC_ERROR; - webkit_glue::WebPluginDelegate* delegate = plugin->webplugin()->delegate(); - return delegate->OpenFileInSandbox(file_name, handle); +// ----------------------------------------------------------------------------- + +static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) { + static NPDevice device_2d = { + Device2DQueryCapability, + Device2DQueryConfig, + Device2DInitializeContext, + Device2DSetStateContext, + Device2DGetStateContext, + Device2DFlushContext, + Device2DDestroyContext, + }; + switch (device_id) { + case NPPepper2DDevice: + return const_cast<NPDevice*>(&device_2d); + default: + return NULL; + } } + #endif // defined(PEPPER_APIS_ENABLED) NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { @@ -872,16 +935,12 @@ NPError NPN_GetValue(NPP id, NPNVariable variable, void *value) { #if defined(PEPPER_APIS_ENABLED) case NPNVPepperExtensions: { - static const NPPepperExtensions kExtensions = { - InitializeRenderContext, - FlushRenderContext, - DestroyRenderContext, - OpenFileInSandbox, + static const NPExtensions kExtensions = { + AcquireDevice, }; // Return a pointer to the canonical function table. - NPPepperExtensions* extensions = - const_cast<NPPepperExtensions*>(&kExtensions); - NPPepperExtensions** exts = reinterpret_cast<NPPepperExtensions**>(value); + NPExtensions* extensions = const_cast<NPExtensions*>(&kExtensions); + NPExtensions** exts = reinterpret_cast<NPExtensions**>(value); *exts = extensions; rv = NPERR_NO_ERROR; break; diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index 2b9c5bb..5a724f1 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -12,7 +12,7 @@ #include "base/string16.h" #include "build/build_config.h" #include "third_party/npapi/bindings/npapi.h" -#include "webkit/glue/pepper/pepper.h" +#include "third_party/npapi/bindings/npapi_extensions.h" #include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h" class FilePath; @@ -127,22 +127,38 @@ class WebPluginDelegate { intptr_t notify_data, intptr_t stream) = 0; - // The following two methods are for use in implementing Pepper renderers. + // The following methods are for use in implementing Pepper renderers. // They should not be called outside of that context. - virtual NPError InitializeRenderContext(NPRenderType type, - NPRenderContext* context) { + + // Pepper 2D device API. + virtual NPError Device2DQueryCapability(int32 capability, int32* value) { return NPERR_GENERIC_ERROR; } - - virtual NPError DestroyRenderContext(NPRenderContext* context) { + virtual NPError Device2DQueryConfig(const NPDeviceContext2DConfig* request, + NPDeviceContext2DConfig* obtain) { return NPERR_GENERIC_ERROR; } - - virtual NPError FlushRenderContext(NPRenderContext* context) { + virtual NPError Device2DInitializeContext( + const NPDeviceContext2DConfig* config, + NPDeviceContext2D* context) { return NPERR_GENERIC_ERROR; } - - virtual NPError OpenFileInSandbox(const char* file_name, void** handle) { + virtual NPError Device2DSetStateContext(NPDeviceContext2D* context, + int32 state, + int32 value) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device2DGetStateContext(NPDeviceContext2D* context, + int32 state, + int32* value) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device2DFlushContext(NPDeviceContext2D* context, + NPDeviceFlushContextCallbackPtr callback, + void* user_data) { + return NPERR_GENERIC_ERROR; + } + virtual NPError Device2DDestroyContext(NPDeviceContext2D* context) { return NPERR_GENERIC_ERROR; } }; diff --git a/webkit/tools/pepper_test_plugin/plugin_object.cc b/webkit/tools/pepper_test_plugin/plugin_object.cc index 8af7591..432bfc4 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.cc +++ b/webkit/tools/pepper_test_plugin/plugin_object.cc @@ -224,11 +224,12 @@ void DrawSampleBitmap(SkCanvas& canvas, int width, int height) { canvas.drawPath(path, paint); } -NPPepperExtensions* pepper = NULL; - -void FlushCallback(NPRenderContext* context, void* user_data) { +void FlushCallback(NPP instance, NPDeviceContext* context, + NPError err, void* user_data) { } +NPExtensions* extensions = NULL; + } // namespace @@ -236,15 +237,19 @@ void FlushCallback(NPRenderContext* context, void* user_data) { PluginObject::PluginObject(NPP npp) : npp_(npp), - test_object_(browser->createobject(npp, GetTestClass())) { - if (!pepper) { + test_object_(browser->createobject(npp, GetTestClass())), + device2d_(NULL) { + if (!extensions) { browser->getvalue(npp_, NPNVPepperExtensions, - reinterpret_cast<void*>(&pepper)); - CHECK(pepper); + reinterpret_cast<void*>(&extensions)); + CHECK(extensions); } + device2d_ = extensions->acquireDevice(npp, NPPepper2DDevice); + CHECK(device2d_); } PluginObject::~PluginObject() { + // FIXME(brettw) destroy the context. browser->releaseobject(test_object_); } @@ -254,26 +259,12 @@ NPClass* PluginObject::GetPluginClass() { } void PluginObject::SetWindow(const NPWindow& window) { - // File test - /* TODO(brettw): remove this when the file stuff is complete. This code is for - testing the OpenFileInSandbox function which is not complete. - { - void* handle = (void*)112358; - NPError err = pepper->openFile(npp_, - "q:\\prj\\src2\\src\\webkit\\tools\\pepper_test_plugin\\README", - &handle); - CHECK(err == NPERR_NO_ERROR); - - char buf[256]; - sprintf(buf, "Got the handle %d", (int)handle); - ::MessageBoxA(NULL, buf, "pepper", 0); - }*/ - size_.set_width(window.width); size_.set_height(window.height); - NPRenderContext context; - pepper->initializeRender(npp_, NPRenderGraphicsRGBA, &context); + NPDeviceContext2DConfig config; + NPDeviceContext2D context; + device2d_->initializeContext(npp_, &config, &context); SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, window.width, window.height); @@ -284,7 +275,7 @@ void PluginObject::SetWindow(const NPWindow& window) { // TODO(brettw) figure out why this cast is necessary, the functions seem to // match. Could be a calling convention mismatch? - NPFlushRenderContextCallbackPtr callback = - reinterpret_cast<NPFlushRenderContextCallbackPtr>(&FlushCallback); - pepper->flushRender(npp_, &context, callback, NULL); + NPDeviceFlushContextCallbackPtr callback = + reinterpret_cast<NPDeviceFlushContextCallbackPtr>(&FlushCallback); + device2d_->flushContext(npp_, &context, callback, NULL); } diff --git a/webkit/tools/pepper_test_plugin/plugin_object.h b/webkit/tools/pepper_test_plugin/plugin_object.h index a45bdc4..1dcbb80 100644 --- a/webkit/tools/pepper_test_plugin/plugin_object.h +++ b/webkit/tools/pepper_test_plugin/plugin_object.h @@ -49,6 +49,8 @@ class PluginObject { NPP npp_; NPObject* test_object_; + NPDevice* device2d_; + gfx::Size size_; DISALLOW_COPY_AND_ASSIGN(PluginObject); |