diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 19:24:28 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 19:24:28 +0000 |
commit | 0a424afc9c94380ecd80967be73cfb684b6ae3f4 (patch) | |
tree | 8741005d16fd3313f9d9430d30bec6497cd63225 | |
parent | 336648ae73fa2d95d5042b00503c406fee1a6d0e (diff) | |
download | chromium_src-0a424afc9c94380ecd80967be73cfb684b6ae3f4.zip chromium_src-0a424afc9c94380ecd80967be73cfb684b6ae3f4.tar.gz chromium_src-0a424afc9c94380ecd80967be73cfb684b6ae3f4.tar.bz2 |
Pepper gamepad support
BUG=79098
Review URL: http://codereview.chromium.org/9085027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117077 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/renderer/pepper_plugin_delegate_impl.cc | 9 | ||||
-rw-r--r-- | content/renderer/pepper_plugin_delegate_impl.h | 10 | ||||
-rw-r--r-- | ppapi/api/dev/ppb_gamepad_dev.idl | 87 | ||||
-rw-r--r-- | ppapi/c/dev/ppb_gamepad_dev.h | 106 | ||||
-rw-r--r-- | ppapi/examples/gamepad/gamepad.cc | 151 | ||||
-rw-r--r-- | ppapi/examples/gamepad/gamepad.html | 17 | ||||
-rw-r--r-- | ppapi/ppapi_shared.gypi | 1 | ||||
-rw-r--r-- | ppapi/ppapi_sources.gypi | 1 | ||||
-rw-r--r-- | ppapi/ppapi_tests.gypi | 13 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.cc | 5 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.h | 4 | ||||
-rw-r--r-- | ppapi/tests/all_c_includes.h | 1 | ||||
-rw-r--r-- | ppapi/thunk/interfaces_ppb_public_dev.h | 1 | ||||
-rw-r--r-- | ppapi/thunk/ppb_gamepad_thunk.cc | 34 | ||||
-rw-r--r-- | ppapi/thunk/ppb_instance_api.h | 7 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 7 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 45 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 5 |
20 files changed, 505 insertions, 8 deletions
diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc index 793543a..8bc1fb8 100644 --- a/content/renderer/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper_plugin_delegate_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -31,6 +31,7 @@ #include "content/common/view_messages.h" #include "content/public/common/content_switches.h" #include "content/public/renderer/content_renderer_client.h" +#include "content/renderer/gamepad_shared_memory_reader.h" #include "content/renderer/gpu/command_buffer_proxy.h" #include "content/renderer/gpu/gpu_channel_host.h" #include "content/renderer/gpu/renderer_gl_context.h" @@ -2035,6 +2036,12 @@ bool PepperPluginDelegateImpl::IsInFullscreenMode() { return render_view_->is_fullscreen(); } +void PepperPluginDelegateImpl::SampleGamepads(WebKit::WebGamepads* data) { + if (!gamepad_shared_memory_reader_.get()) + gamepad_shared_memory_reader_.reset(new content::GamepadSharedMemoryReader); + gamepad_shared_memory_reader_->SampleGamepads(*data); +} + bool PepperPluginDelegateImpl::IsPageVisible() const { return !render_view_->is_hidden(); } diff --git a/content/renderer/pepper_plugin_delegate_impl.h b/content/renderer/pepper_plugin_delegate_impl.h index 2ef8fb7..22f5ab2 100644 --- a/content/renderer/pepper_plugin_delegate_impl.h +++ b/content/renderer/pepper_plugin_delegate_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -30,6 +30,10 @@ class FilePath; class PepperPluginDelegateImpl; class RenderViewImpl; +namespace content { +class GamepadSharedMemoryReader; +} + namespace gfx { class Point; class Rect; @@ -50,6 +54,7 @@ class PluginModule; namespace WebKit { class WebFileChooserCompletion; +class WebGamepads; class WebMouseEvent; struct WebCompositionUnderline; struct WebFileChooserParams; @@ -385,6 +390,7 @@ class PepperPluginDelegateImpl virtual void DidReceiveMouseEvent( webkit::ppapi::PluginInstance* instance) OVERRIDE; virtual bool IsInFullscreenMode() OVERRIDE; + virtual void SampleGamepads(WebKit::WebGamepads* data) OVERRIDE; virtual bool IsPageVisible() const OVERRIDE; // RenderViewObserver implementation. @@ -496,6 +502,8 @@ class PepperPluginDelegateImpl // when it is destroyed via InstanceDeleted(). webkit::ppapi::PluginInstance* last_mouse_event_target_; + scoped_ptr<content::GamepadSharedMemoryReader> gamepad_shared_memory_reader_; + DISALLOW_COPY_AND_ASSIGN(PepperPluginDelegateImpl); }; diff --git a/ppapi/api/dev/ppb_gamepad_dev.idl b/ppapi/api/dev/ppb_gamepad_dev.idl new file mode 100644 index 0000000..209a21c --- /dev/null +++ b/ppapi/api/dev/ppb_gamepad_dev.idl @@ -0,0 +1,87 @@ +/* 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 file defines the <code>PPB_Gamepad_Dev</code> interface, which + * provides access to gamepad devices. + */ + +label Chrome { + M18 = 0.1 +}; + +/** + * The data for one gamepad device. + */ +struct PP_GamepadData_Dev { + /** + * Is there a gamepad connected at this index? If this is false, no other + * data in this structure is valid. + */ + char connected; + + /** + * String identifier for the type of device/manufacturer. + */ + uint16_t[128] id; + + /** + * Monotonically increasing value that is incremented when the data have + * been updated. + */ + uint64_t timestamp; + + /** + * Number of valid elements in the |axes| array. + */ + uint32_t axes_length; + + /** + * Normalized values for the axes, indices valid up to |axesLength|-1. Axis + * values range from -1..1, and are in order of "importance". + */ + float_t[16] axes; + + /** + * Number of valid elements in the |buttons| array. + */ + uint32_t buttons_length; + + /** + * Normalized values for the buttons, indices valid up to |buttonsLength| + * - 1. Button values range from 0..1, and are in order of importance. + */ + float_t[32] buttons; +}; + +/** + * The data for all gamepads connected to the system. + */ +struct PP_GamepadsData_Dev { + /** + * Number of valid elements in the |items| array. + */ + uint32_t length; + + /** + * Data for an individual gamepad device connected to the system. + */ + PP_GamepadData_Dev[4] items; +}; + +/** + * The <code>PPB_Gamepad_Dev</code> interface allows retrieving data from + * gamepad/joystick devices that are connected to the system. + */ +[version=0.1, macro="PPB_GAMEPAD_DEV_INTERFACE"] +interface PPB_Gamepad_Dev { + /** + * Samples the current state of the connected gamepads. + */ + void SampleGamepads( + [in] PP_Instance instance, + [out] PP_GamepadsData_Dev data); + +}; diff --git a/ppapi/c/dev/ppb_gamepad_dev.h b/ppapi/c/dev/ppb_gamepad_dev.h new file mode 100644 index 0000000..63197bc --- /dev/null +++ b/ppapi/c/dev/ppb_gamepad_dev.h @@ -0,0 +1,106 @@ +/* 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. + */ + +/* From dev/ppb_gamepad_dev.idl modified Mon Jan 9 13:16:43 2012. */ + +#ifndef PPAPI_C_DEV_PPB_GAMEPAD_DEV_H_ +#define PPAPI_C_DEV_PPB_GAMEPAD_DEV_H_ + +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_stdint.h" + +#define PPB_GAMEPAD_DEV_INTERFACE_0_1 "PPB_Gamepad(Dev);0.1" +#define PPB_GAMEPAD_DEV_INTERFACE PPB_GAMEPAD_DEV_INTERFACE_0_1 + +/** + * @file + * This file defines the <code>PPB_Gamepad_Dev</code> interface, which + * provides access to gamepad devices. + */ + + +/** + * @addtogroup Structs + * @{ + */ +/** + * The data for one gamepad device. + */ +struct PP_GamepadData_Dev { + /** + * Is there a gamepad connected at this index? If this is false, no other + * data in this structure is valid. + */ + char connected; + /** + * String identifier for the type of device/manufacturer. + */ + uint16_t id[128]; + /** + * Monotonically increasing value that is incremented when the data have + * been updated. + */ + uint64_t timestamp; + /** + * Number of valid elements in the |axes| array. + */ + uint32_t axes_length; + /** + * Normalized values for the axes, indices valid up to |axesLength|-1. Axis + * values range from -1..1, and are in order of "importance". + */ + float axes[16]; + /** + * Number of valid elements in the |buttons| array. + */ + uint32_t buttons_length; + /** + * Normalized values for the buttons, indices valid up to |buttonsLength| + * - 1. Button values range from 0..1, and are in order of importance. + */ + float buttons[32]; +}; + +/** + * The data for all gamepads connected to the system. + */ +struct PP_GamepadsData_Dev { + /** + * Number of valid elements in the |items| array. + */ + uint32_t length; + /** + * Data for an individual gamepad device connected to the system. + */ + struct PP_GamepadData_Dev items[4]; +}; +/** + * @} + */ + +/** + * @addtogroup Interfaces + * @{ + */ +/** + * The <code>PPB_Gamepad_Dev</code> interface allows retrieving data from + * gamepad/joystick devices that are connected to the system. + */ +struct PPB_Gamepad_Dev_0_1 { + /** + * Samples the current state of the connected gamepads. + */ + void (*SampleGamepads)(PP_Instance instance, + struct PP_GamepadsData_Dev* data); +}; + +typedef struct PPB_Gamepad_Dev_0_1 PPB_Gamepad_Dev; +/** + * @} + */ + +#endif /* PPAPI_C_DEV_PPB_GAMEPAD_DEV_H_ */ + diff --git a/ppapi/examples/gamepad/gamepad.cc b/ppapi/examples/gamepad/gamepad.cc new file mode 100644 index 0000000..60ef589 --- /dev/null +++ b/ppapi/examples/gamepad/gamepad.cc @@ -0,0 +1,151 @@ +// 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. + +#include <cmath> +#include <stdarg.h> +#include <stdio.h> + +#include "ppapi/c/dev/ppb_console_dev.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" +#include "ppapi/c/ppb_input_event.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/graphics_2d.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/input_event.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/logging.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/rect.h" +#include "ppapi/cpp/var.h" +#include "ppapi/cpp/view.h" +#include "ppapi/utility/completion_callback_factory.h" + +void FillRect(pp::ImageData* image, int left, int top, int width, int height, + uint32_t color) { + for (int y = std::max(0, top); + y < std::min(image->size().height() - 1, top + height); + y++) { + for (int x = std::max(0, left); + x < std::min(image->size().width() - 1, left + width); + x++) + *image->GetAddr32(pp::Point(x, y)) = color; + } +} + +class MyInstance : public pp::Instance { + public: + explicit MyInstance(PP_Instance instance) + : pp::Instance(instance), + width_(0), + height_(0), + callback_factory_(this), + gamepad_(NULL) { + } + virtual ~MyInstance() {} + + virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { + gamepad_ = reinterpret_cast<const PPB_Gamepad_Dev*>( + pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_DEV_INTERFACE)); + if (!gamepad_) + return false; + + RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | + PP_INPUTEVENT_CLASS_KEYBOARD); + return true; + } + + virtual void DidChangeView(const pp::View& view) { + pp::Rect rect = view.GetRect(); + if (rect.size().width() == width_ && + rect.size().height() == height_) + return; // We don't care about the position, only the size. + + width_ = rect.size().width(); + height_ = rect.size().height(); + + device_context_ = pp::Graphics2D(this, pp::Size(width_, height_), false); + if (!BindGraphics(device_context_)) + return; + + Paint(); + } + + void OnFlush(int32_t) { + Paint(); + } + + private: + void Paint() { + pp::ImageData image = PaintImage(device_context_.size()); + if (!image.is_null()) { + device_context_.ReplaceContents(&image); + device_context_.Flush( + callback_factory_.NewRequiredCallback(&MyInstance::OnFlush)); + } else { + printf("NullImage\n"); + } + } + + pp::ImageData PaintImage(const pp::Size& size) { + pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, false); + if (image.is_null()) + return image; + + PP_GamepadsData_Dev gamepad_data; + gamepad_->SampleGamepads(pp_instance(), &gamepad_data); + + int width2 = size.width() / 2; + int height2 = size.height() / 2; + // Draw 2 axes + for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) { + int x = static_cast<int>( + gamepad_data.items[0].axes[i + 0] * width2 + width2); + int y = static_cast<int>( + gamepad_data.items[0].axes[i + 1] * height2 + height2); + uint32_t box_bgra = 0x80000000; // Alpha 50%. + FillRect(&image, x - 3, y - 3, 7, 7, box_bgra); + } + + for (size_t i = 0; i < gamepad_data.items[0].buttons_length; ++i) { + float button_val = gamepad_data.items[0].buttons[i]; + uint32_t colour = static_cast<uint32_t>((button_val * 192) + 63) << 24; + int x = i * 8 + 10; + int y = 10; + FillRect(&image, x - 3, y - 3, 7, 7, colour); + } + return image; + } + + int width_; + int height_; + + pp::CompletionCallbackFactory<MyInstance> callback_factory_; + + const PPB_Gamepad_Dev* gamepad_; + + pp::Graphics2D device_context_; +}; + +// This object is the global object representing this plugin library as long +// as it is loaded. +class MyModule : public pp::Module { + public: + MyModule() : pp::Module() {} + virtual ~MyModule() {} + + // Override CreateInstance to create your customized Instance object. + virtual pp::Instance* CreateInstance(PP_Instance instance) { + return new MyInstance(instance); + } +}; + +namespace pp { + +// Factory function for your specialization of the Module object. +Module* CreateModule() { + return new MyModule(); +} + +} // namespace pp + diff --git a/ppapi/examples/gamepad/gamepad.html b/ppapi/examples/gamepad/gamepad.html new file mode 100644 index 0000000..6e400dd --- /dev/null +++ b/ppapi/examples/gamepad/gamepad.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<html> + <!-- + 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. + --> +<head> + <title>Gamepad Example</title> +</head> +<body> +<div> + <object id="plugin" type="application/x-ppapi-example-gamepad" + width="300" height="300" border="2px"></object> +</div> +</body> +</html> diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 0cafb51..2802b5d 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -158,6 +158,7 @@ 'thunk/ppb_font_api.h', 'thunk/ppb_font_thunk.cc', 'thunk/ppb_fullscreen_thunk.cc', + 'thunk/ppb_gamepad_thunk.cc', 'thunk/ppb_gles_chromium_texture_mapping_thunk.cc', 'thunk/ppb_graphics_2d_api.h', 'thunk/ppb_graphics_2d_thunk.cc', diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index f517a12..a2c6884 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -61,6 +61,7 @@ 'c/dev/ppb_find_dev.h', 'c/dev/ppb_font_dev.h', 'c/dev/ppb_fullscreen_dev.h', + 'c/dev/ppb_gamepad_dev.h', 'c/dev/ppb_ime_input_event_dev.h', 'c/dev/ppb_memory_dev.h', 'c/dev/ppb_resource_array_dev.h', diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi index 26d2527..0e23631 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -1,4 +1,4 @@ -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# 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. @@ -200,6 +200,17 @@ }, { + 'target_name': 'ppapi_example_gamepad', + 'dependencies': [ + 'ppapi_example_skeleton', + 'ppapi.gyp:ppapi_cpp', + ], + 'sources': [ + 'examples/gamepad/gamepad.cc', + ], + }, + + { 'target_name': 'ppapi_example_c_stub', 'dependencies': [ 'ppapi_example_skeleton', diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index f8dd8a2..1a71966 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -267,6 +267,11 @@ PP_Bool PPB_Instance_Proxy::FlashGetScreenSize(PP_Instance instance, return result; } +void PPB_Instance_Proxy::SampleGamepads(PP_Instance instance, + PP_GamepadsData_Dev* data) { + NOTIMPLEMENTED(); +} + int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance, uint32_t event_classes) { dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents( diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index a88bd6f..0ce2562 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -75,6 +75,8 @@ class PPB_Instance_Proxy : public InterfaceProxy, PP_Bool fullscreen) OVERRIDE; virtual PP_Bool FlashGetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE; + virtual void SampleGamepads(PP_Instance instance, PP_GamepadsData_Dev* data) + OVERRIDE; virtual int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) OVERRIDE; virtual int32_t RequestFilteringInputEvents(PP_Instance instance, diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index 10b66d3..6189968 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -21,6 +21,7 @@ #include "ppapi/c/dev/ppb_find_dev.h" #include "ppapi/c/dev/ppb_font_dev.h" #include "ppapi/c/dev/ppb_fullscreen_dev.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" #include "ppapi/c/dev/ppb_ime_input_event_dev.h" #include "ppapi/c/dev/ppb_layer_compositor_dev.h" #include "ppapi/c/dev/ppb_memory_dev.h" diff --git a/ppapi/thunk/interfaces_ppb_public_dev.h b/ppapi/thunk/interfaces_ppb_public_dev.h index f72fa7c..de3b62b 100644 --- a/ppapi/thunk/interfaces_ppb_public_dev.h +++ b/ppapi/thunk/interfaces_ppb_public_dev.h @@ -43,6 +43,7 @@ PROXIED_IFACE(PPB_FileChooser, PPB_FILECHOOSER_DEV_INTERFACE_0_5, PROXIED_IFACE(PPB_Font, PPB_FONT_DEV_INTERFACE_0_6, PPB_Font_Dev_0_6) PROXIED_IFACE(PPB_Instance, PPB_CHAR_SET_DEV_INTERFACE_0_4, PPB_CharSet_Dev_0_4) PROXIED_IFACE(PPB_Instance, PPB_CONSOLE_DEV_INTERFACE_0_1, PPB_Console_Dev_0_1) +PROXIED_IFACE(PPB_Instance, PPB_GAMEPAD_DEV_INTERFACE_0_1, PPB_Gamepad_Dev_0_1) PROXIED_IFACE(PPB_Instance, PPB_URLUTIL_DEV_INTERFACE_0_6, PPB_URLUtil_Dev_0_6) UNPROXIED_IFACE(PPB_Instance, PPB_ZOOM_DEV_INTERFACE_0_2, PPB_Zoom_Dev_0_2) UNPROXIED_IFACE(PPB_LayerCompositor, PPB_LAYER_COMPOSITOR_DEV_INTERFACE_0_2, diff --git a/ppapi/thunk/ppb_gamepad_thunk.cc b/ppapi/thunk/ppb_gamepad_thunk.cc new file mode 100644 index 0000000..9bf2122 --- /dev/null +++ b/ppapi/thunk/ppb_gamepad_thunk.cc @@ -0,0 +1,34 @@ +// 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. + +#include "ppapi/c/dev/ppb_gamepad_dev.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_instance_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +void SampleGamepads(PP_Instance instance, PP_GamepadsData_Dev* data) { + EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.failed()) + return; + enter.functions()->SampleGamepads(instance, data); +} + +const PPB_Gamepad_Dev g_ppb_gamepad_thunk = { + &SampleGamepads, +}; + +} // namespace + +const PPB_Gamepad_Dev* GetPPB_Gamepad_Dev_0_1_Thunk() { + return &g_ppb_gamepad_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index 8151479..013f61b 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -1,10 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. #ifndef PPAPI_THUNK_INSTANCE_API_H_ #define PPAPI_THUNK_INSTANCE_API_H_ +#include "ppapi/c/dev/ppb_gamepad_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/ppb_instance.h" @@ -71,6 +72,10 @@ class PPB_Instance_FunctionAPI { PP_Bool fullscreen) = 0; virtual PP_Bool FlashGetScreenSize(PP_Instance instance, PP_Size* size) = 0; + // Gamepad. + virtual void SampleGamepads(PP_Instance instance, + PP_GamepadsData_Dev* data) = 0; + // InputEvent. virtual int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) = 0; diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index a991c50..da371c54 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -8,6 +8,7 @@ #include "base/message_loop_proxy.h" #include "ppapi/c/pp_errors.h" #include "ppapi/shared_impl/ppapi_preferences.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" namespace webkit { @@ -361,6 +362,10 @@ void MockPluginDelegate::DidChangeCursor(PluginInstance* instance, void MockPluginDelegate::DidReceiveMouseEvent(PluginInstance* instance) { } +void MockPluginDelegate::SampleGamepads(WebKit::WebGamepads* data) { + data->length = 0; +} + bool MockPluginDelegate::IsInFullscreenMode() { return false; } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 7fe0155..fbd961a 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -153,6 +153,7 @@ class MockPluginDelegate : public PluginDelegate { virtual void DidChangeCursor(PluginInstance* instance, const WebKit::WebCursorInfo& cursor); virtual void DidReceiveMouseEvent(PluginInstance* instance); + virtual void SampleGamepads(WebKit::WebGamepads* data) OVERRIDE; virtual bool IsInFullscreenMode(); virtual bool IsPageVisible() const; }; diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index af93ec8..6f9a17e 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -59,6 +59,7 @@ class PlatformCanvas; namespace WebKit { class WebFileChooserCompletion; +class WebGamepads; struct WebCursorInfo; struct WebFileChooserParams; } @@ -515,6 +516,9 @@ class PluginDelegate { // Determines if the browser entered fullscreen mode. virtual bool IsInFullscreenMode() = 0; + // Retrieve current gamepad data. + virtual void SampleGamepads(WebKit::WebGamepads* data) = 0; + // Returns true if the containing page is visible. virtual bool IsPageVisible() const = 0; }; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 63536bc..b3782d3 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -14,6 +14,7 @@ #include "base/utf_string_conversions.h" #include "ppapi/c/dev/ppb_console_dev.h" #include "ppapi/c/dev/ppb_find_dev.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" #include "ppapi/c/dev/ppb_zoom_dev.h" #include "ppapi/c/dev/ppp_find_dev.h" #include "ppapi/c/dev/ppp_selection_dev.h" @@ -45,6 +46,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" @@ -226,6 +228,13 @@ COMPILE_ASSERT_MATCHING_ENUM(TypeGrabbing, PP_CURSORTYPE_GRABBING); // Do not assert WebCursorInfo::TypeCustom == PP_CURSORTYPE_CUSTOM; // PP_CURSORTYPE_CUSTOM is pinned to allow new cursor types. +// Ensure conversion from WebKit::WebGamepads to PP_GamepadsData_Dev is safe. +// See also DCHECKs in SampleGamepads below. +COMPILE_ASSERT(sizeof(WebKit::WebGamepads) == sizeof(PP_GamepadsData_Dev), + size_difference); +COMPILE_ASSERT(sizeof(WebKit::WebGamepad) == sizeof(PP_GamepadData_Dev), + size_difference); + // Sets |*security_origin| to be the WebKit security origin associated with the // document containing the given plugin instance. On success, returns true. If // the instance is invalid, returns false and |*security_origin| will be @@ -1310,6 +1319,42 @@ int32_t PluginInstance::Navigate(PPB_URLRequestInfo_Impl* request, return PP_OK; } +void PluginInstance::SampleGamepads(PP_Instance instance, + PP_GamepadsData_Dev* data) { + + // Because the WebKit objects have trivial ctors, using offsetof doesn't + // work. Instead use this version based on src/v8/src/globals.h. This + // workaround doesn't work in constant expressions as required for + // COMPILE_ASSERT, so DCHECK instead. + +#define OFFSET_OF(type, field) \ + (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4) + +#define DCHECK_GAMEPADS_OFFSET(webkit_name, pp_name) \ + DCHECK(OFFSET_OF(WebKit::WebGamepads, webkit_name) \ + == OFFSET_OF(PP_GamepadsData_Dev, pp_name)) + +#define DCHECK_GAMEPAD_OFFSET(webkit_name, pp_name) \ + DCHECK(OFFSET_OF(WebKit::WebGamepad, webkit_name) \ + == OFFSET_OF(PP_GamepadData_Dev, pp_name)) + + DCHECK_GAMEPADS_OFFSET(length, length); + DCHECK_GAMEPADS_OFFSET(items, items); + DCHECK_GAMEPAD_OFFSET(connected, connected); + DCHECK_GAMEPAD_OFFSET(id, id); + DCHECK_GAMEPAD_OFFSET(timestamp, timestamp); + DCHECK_GAMEPAD_OFFSET(axesLength, axes_length); + DCHECK_GAMEPAD_OFFSET(axes, axes); + DCHECK_GAMEPAD_OFFSET(buttonsLength, buttons_length); + DCHECK_GAMEPAD_OFFSET(buttons, buttons); + +#undef OFFSET_OF +#undef DCHECK_GAMEPADS_OFFSET +#undef DCHECK_GAMEPAD_OFFSET + + delegate()->SampleGamepads(reinterpret_cast<WebKit::WebGamepads*>(data)); +} + bool PluginInstance::IsViewAccelerated() { if (!container_) return false; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index cbafec1..3caef5c 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -16,6 +16,7 @@ #include "base/string16.h" #include "googleurl/src/gurl.h" #include "ppapi/c/dev/pp_cursor_type_dev.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/dev/ppp_find_dev.h" #include "ppapi/c/dev/ppp_selection_dev.h" @@ -287,6 +288,10 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : const char* target, bool from_user_action); + // Implementation of PPB_Gamepad. + void SampleGamepads(PP_Instance instance, PP_GamepadsData_Dev* data) + OVERRIDE; + // Implementation of PPP_Messaging. void HandleMessage(PP_Var message); |