diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 19:54:30 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 19:54:30 +0000 |
commit | f511881bed1a46d2110f36e6b60e28f2b306b935 (patch) | |
tree | 58d69490432a1176a56ee2c0bdd6dd8016162e46 /ppapi | |
parent | 5d67452f563f0d6eddc932dd67f7e84579b77831 (diff) | |
download | chromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.zip chromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.tar.gz chromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.tar.bz2 |
Add a skeleton gamepad resource.
This implements the skeleton of the gamepad resource for the IPC proxy. It is not actually hooked up. Hooking it up will require moving some gamepad lock code to a shared location.
This also hooks up the browser message routing for implementing resource hosts in the browser process.
BUG=
Review URL: https://chromiumcodereview.appspot.com/10824272
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/host/dispatch_host_message.h | 32 | ||||
-rw-r--r-- | ppapi/ppapi_proxy.gypi | 2 | ||||
-rw-r--r-- | ppapi/ppapi_shared.gypi | 1 | ||||
-rw-r--r-- | ppapi/proxy/gamepad_resource.cc | 58 | ||||
-rw-r--r-- | ppapi/proxy/gamepad_resource.h | 56 | ||||
-rw-r--r-- | ppapi/proxy/plugin_dispatcher.cc | 1 | ||||
-rw-r--r-- | ppapi/proxy/plugin_dispatcher.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 6 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.cc | 18 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.h | 3 | ||||
-rw-r--r-- | ppapi/thunk/ppb_gamepad_api.h | 25 | ||||
-rw-r--r-- | ppapi/thunk/ppb_gamepad_thunk.cc | 15 | ||||
-rw-r--r-- | ppapi/thunk/ppb_instance_api.h | 4 |
13 files changed, 203 insertions, 22 deletions
diff --git a/ppapi/host/dispatch_host_message.h b/ppapi/host/dispatch_host_message.h index 070b746..9a3fae5 100644 --- a/ppapi/host/dispatch_host_message.h +++ b/ppapi/host/dispatch_host_message.h @@ -61,20 +61,28 @@ inline int32_t DispatchResourceCall(ObjT* obj, Method method, return (obj->*method)(context, arg.a, arg.b, arg.c, arg.d, arg.e); } +// Note that this only works for message with 1 or more parameters. For +// 0-parameter messages you need to use the _0 version below (since there are +// no Params in the message). #define PPAPI_DISPATCH_HOST_RESOURCE_CALL(msg_class, member_func) \ case msg_class::ID: { \ - TRACK_RUN_IN_IPC_HANDLER(member_func); \ - msg_class::Schema::Param p; \ - if (msg_class::Read(&ipc_message__, &p)) { \ - return ppapi::host::DispatchResourceCall( \ - this, \ - &_IpcMessageHandlerClass::member_func, \ - context, p); \ - } else { \ - return PP_ERROR_FAILED; \ - } \ - } \ - break; + TRACK_RUN_IN_IPC_HANDLER(member_func); \ + msg_class::Schema::Param p; \ + if (msg_class::Read(&ipc_message__, &p)) { \ + return ppapi::host::DispatchResourceCall( \ + this, \ + &_IpcMessageHandlerClass::member_func, \ + context, p); \ + } \ + return PP_ERROR_FAILED; \ + } + +#define PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(msg_class, member_func) \ + case msg_class::ID: { \ + TRACK_RUN_IN_IPC_HANDLER(member_func); \ + return member_func(context); \ + } + } // namespace host } // namespace ppapi diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index ca15e63..6bf1d88 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -27,6 +27,8 @@ 'proxy/enter_proxy.h', 'proxy/file_chooser_resource.cc', 'proxy/file_chooser_resource.h', + 'proxy/gamepad_resource.cc', + 'proxy/gamepad_resource.h', 'proxy/host_dispatcher.cc', 'proxy/host_dispatcher.h', 'proxy/host_var_serialization_rules.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 1c186b5..06f6e00 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -170,6 +170,7 @@ 'thunk/ppb_flash_message_loop_thunk.cc', 'thunk/ppb_flash_thunk.cc', 'thunk/ppb_fullscreen_thunk.cc', + 'thunk/ppb_gamepad_api.h', 'thunk/ppb_gamepad_thunk.cc', 'thunk/ppb_gles_chromium_texture_mapping_thunk.cc', 'thunk/ppb_graphics_2d_api.h', diff --git a/ppapi/proxy/gamepad_resource.cc b/ppapi/proxy/gamepad_resource.cc new file mode 100644 index 0000000..21ee02d --- /dev/null +++ b/ppapi/proxy/gamepad_resource.cc @@ -0,0 +1,58 @@ +// 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/proxy/gamepad_resource.h" + +#include <string.h> + +#include "ppapi/c/ppb_gamepad.h" +#include "ppapi/proxy/dispatch_reply_message.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace ppapi { +namespace proxy { + +GamepadResource::GamepadResource(Connection connection, PP_Instance instance) + : PluginResource(connection, instance), + buffer_(NULL) { + SendCreateToBrowser(PpapiHostMsg_Gamepad_Create()); + CallBrowser(PpapiHostMsg_Gamepad_RequestMemory()); +} + +GamepadResource::~GamepadResource() { +} + +void GamepadResource::Sample(PP_GamepadsSampleData* data) { + if (!buffer_) { + // Browser hasn't sent back our shared memory, give the plugin gamepad + // data corresponding to "not connected". + memset(data, 0, sizeof(PP_GamepadsSampleData)); + } else { + memcpy(data, buffer_, sizeof(PP_GamepadsSampleData)); + } +} + +void GamepadResource::OnReplyReceived(const ResourceMessageReplyParams& params, + const IPC::Message& msg) { + IPC_BEGIN_MESSAGE_MAP(GamepadResource, msg) + PPAPI_DISPATCH_RESOURCE_REPLY(PpapiPluginMsg_Gamepad_SendMemory, + OnPluginMsgSendMemory) + IPC_END_MESSAGE_MAP() +} + +void GamepadResource::OnPluginMsgSendMemory( + const ResourceMessageReplyParams& params, + base::SharedMemoryHandle shared_memory_handle) { + /* TODO(brettw) implement this when we have shared gamepad code. It would be + something like this: + shared_memory_.reset( + new base::SharedMemory(shared_memory_handle, true)); + CHECK(shared_memory_->Map(sizeof(GamepadHardwareBuffer))); + void *memory = shared_memory_->memory(); + // Use the memory... + */ +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/gamepad_resource.h b/ppapi/proxy/gamepad_resource.h new file mode 100644 index 0000000..61d66b0 --- /dev/null +++ b/ppapi/proxy/gamepad_resource.h @@ -0,0 +1,56 @@ +// 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_PROXY_GAMEPAD_RESOURCE_H_ +#define PPAPI_PROXY_GAMEPAD_RESOURCE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "base/shared_memory.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/thunk/ppb_gamepad_api.h" + +struct PP_GamepadsSampleData; + +namespace base { +class SharedMemory; +} + +namespace ppapi { +namespace proxy { + +// This class is a bit weird. It isn't a true resource from the plugin's +// perspective. But we need to make requests to the browser and get replies. +// It's more convenient to do this as a resource, so the instance just +// maintains an internal lazily instantiated copy of this resource. +class PPAPI_PROXY_EXPORT GamepadResource + : public PluginResource, + public thunk::PPB_Gamepad_API { + public: + GamepadResource(Connection connection, PP_Instance instance); + virtual ~GamepadResource(); + + // PPB_Gamepad_API. + virtual void Sample(PP_GamepadsSampleData* data) OVERRIDE; + + private: + // PluginResource override. + virtual void OnReplyReceived(const ResourceMessageReplyParams& params, + const IPC::Message& msg) OVERRIDE; + + void OnPluginMsgSendMemory(const ResourceMessageReplyParams& params, + base::SharedMemoryHandle shared_memory_handle); + + scoped_ptr<base::SharedMemory> shared_memory_; + void* buffer_; + + DISALLOW_COPY_AND_ASSIGN(GamepadResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_GAMEPAD_RESOURCE_H_ diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index 4c50653..0e406db 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -14,6 +14,7 @@ #include "base/debug/trace_event.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppp_instance.h" +#include "ppapi/proxy/gamepad_resource.h" #include "ppapi/proxy/interface_list.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/plugin_message_filter.h" diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index 5cf1967..ba46464 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -34,6 +34,7 @@ class ResourceCreationAPI; namespace proxy { +class GamepadResource; class ResourceMessageReplyParams; // Used to keep track of per-instance data. @@ -48,6 +49,9 @@ struct InstanceData { // When non-NULL, indicates the callback to execute when mouse lock is lost. scoped_refptr<TrackedCallback> mouse_lock_callback; + // Lazily created the first time the plugin requests gamepad data. + scoped_refptr<GamepadResource> gamepad_resource; + // Calls to |RequestSurroundingText()| are done by posted tasks. Track whether // a) a task is pending, to avoid redundant calls, and b) whether we should // actually call |RequestSurroundingText()|, to avoid stale calls (i.e., diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index f35b3e8..a5a9cfb 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1530,3 +1530,9 @@ IPC_MESSAGE_CONTROL4(PpapiHostMsg_FileChooser_Show, std::vector<std::string> /* accept_mime_types */) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileChooser_ShowReply, std::vector<ppapi::PPB_FileRef_CreateInfo> /* files */) + +// Gamepad. +IPC_MESSAGE_CONTROL0(PpapiHostMsg_Gamepad_Create) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_Gamepad_RequestMemory) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_Gamepad_SendMemory, + base::SharedMemoryHandle /* handle */) diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index e9eaf35..01fae69 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -14,6 +14,7 @@ #include "ppapi/c/private/pp_content_decryptor.h" #include "ppapi/proxy/content_decryptor_private_serializer.h" #include "ppapi/proxy/enter_proxy.h" +#include "ppapi/proxy/gamepad_resource.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_proxy_delegate.h" @@ -314,9 +315,20 @@ thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() { return static_cast<PPB_Flash_Proxy*>(ip); } -void PPB_Instance_Proxy::SampleGamepads(PP_Instance instance, - PP_GamepadsSampleData* data) { - NOTIMPLEMENTED(); +thunk::PPB_Gamepad_API* PPB_Instance_Proxy::GetGamepadAPI( + PP_Instance instance) { + InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> + GetInstanceData(instance); + if (!data) + return NULL; + + if (!data->gamepad_resource.get()) { + Connection connection( + PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(), + dispatcher()); + data->gamepad_resource = new GamepadResource(connection, instance); + } + return data->gamepad_resource.get(); } int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance, diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index 9da6659..b2503a4 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -69,8 +69,7 @@ class PPB_Instance_Proxy : public InterfaceProxy, virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE; virtual thunk::PPB_Flash_API* GetFlashAPI() OVERRIDE; - virtual void SampleGamepads(PP_Instance instance, - PP_GamepadsSampleData* data) OVERRIDE; + virtual thunk::PPB_Gamepad_API* GetGamepadAPI(PP_Instance instance) OVERRIDE; virtual int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) OVERRIDE; virtual int32_t RequestFilteringInputEvents(PP_Instance instance, diff --git a/ppapi/thunk/ppb_gamepad_api.h b/ppapi/thunk/ppb_gamepad_api.h new file mode 100644 index 0000000..ee7199a --- /dev/null +++ b/ppapi/thunk/ppb_gamepad_api.h @@ -0,0 +1,25 @@ +// 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_PPB_GAMEPAD_API_H_ +#define PPAPI_THUNK_PPB_GAMEPAD_API_H_ + +#include "ppapi/thunk/ppapi_thunk_export.h" + +struct PP_GamepadsSampleData; + +namespace ppapi { +namespace thunk { + +class PPAPI_THUNK_EXPORT PPB_Gamepad_API { + public: + virtual ~PPB_Gamepad_API() {} + + virtual void Sample(PP_GamepadsSampleData* data) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_GAMEPAD_API_H_ diff --git a/ppapi/thunk/ppb_gamepad_thunk.cc b/ppapi/thunk/ppb_gamepad_thunk.cc index 61b3195..3aeedb5 100644 --- a/ppapi/thunk/ppb_gamepad_thunk.cc +++ b/ppapi/thunk/ppb_gamepad_thunk.cc @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <string.h> + #include "ppapi/c/ppb_gamepad.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_gamepad_api.h" #include "ppapi/thunk/ppb_instance_api.h" #include "ppapi/thunk/resource_creation_api.h" @@ -15,9 +18,15 @@ namespace { void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData* data) { EnterInstance enter(instance); - if (enter.failed()) - return; - enter.functions()->SampleGamepads(instance, data); + if (enter.succeeded()) { + PPB_Gamepad_API* api = enter.functions()->GetGamepadAPI(instance); + if (api) { + api->Sample(data); + return; + } + } + // Failure, zero out. + memset(data, 0, sizeof(PP_GamepadsSampleData)); } const PPB_Gamepad g_ppb_gamepad_thunk = { diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index 10868dd..ef80609 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -37,6 +37,7 @@ struct ViewData; namespace thunk { class PPB_Flash_API; +class PPB_Gamepad_API; class PPB_Instance_API { public: @@ -90,8 +91,7 @@ class PPB_Instance_API { virtual PPB_Flash_API* GetFlashAPI() = 0; // Gamepad. - virtual void SampleGamepads(PP_Instance instance, - PP_GamepadsSampleData* data) = 0; + virtual PPB_Gamepad_API* GetGamepadAPI(PP_Instance instance) = 0; // InputEvent. virtual int32_t RequestInputEvents(PP_Instance instance, |