Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: ppapi/proxy/gamepad_resource.cc

Issue 10824272: Add a skeleton gamepad resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/proxy/gamepad_resource.h"
6
7 #include <string.h>
8
9 #include "ppapi/c/ppb_gamepad.h"
10 #include "ppapi/proxy/dispatch_reply_message.h"
11 #include "ppapi/proxy/ppapi_messages.h"
12
13 namespace ppapi {
14 namespace proxy {
15
16 GamepadResource::GamepadResource(Connection connection, PP_Instance instance)
17 : PluginResource(connection, instance),
18 buffer_(NULL) {
19 SendCreateToBrowser(PpapiHostMsg_Gamepad_Create());
20 CallBrowser(PpapiHostMsg_Gamepad_RequestMemory());
21 }
22
23 GamepadResource::~GamepadResource() {
24 }
25
26 void GamepadResource::Sample(PP_GamepadsSampleData* data) {
27 if (!buffer_) {
28 // Browser hasn't sent back our shared memory, give the plugin gamepad
29 // data corresponding to "not connected".
30 memset(data, 0, sizeof(PP_GamepadsSampleData));
31 } else {
32 memcpy(data, buffer_, sizeof(PP_GamepadsSampleData));
33 }
34 }
35
36 void GamepadResource::OnReplyReceived(const ResourceMessageReplyParams& params,
37 const IPC::Message& msg) {
38 IPC_BEGIN_MESSAGE_MAP(GamepadResource, msg)
39 PPAPI_DISPATCH_RESOURCE_REPLY(PpapiPluginMsg_Gamepad_SendMemory,
40 OnPluginMsgSendMemory)
41 IPC_END_MESSAGE_MAP()
42 }
43
44 void GamepadResource::OnPluginMsgSendMemory(
45 const ResourceMessageReplyParams& params,
46 base::SharedMemoryHandle shared_memory_handle) {
47 /* TODO(brettw) implement this when we have shared gamepad code. It would be
48 something like this:
49 shared_memory_.reset(
50 new base::SharedMemory(shared_memory_handle, true));
51 CHECK(shared_memory_->Map(sizeof(GamepadHardwareBuffer)));
52 void *memory = shared_memory_->memory();
53 // Use the memory...
54 */
55 }
56
57 } // namespace proxy
58 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698