OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_buffer_proxy.h" | 5 #include "ppapi/proxy/ppb_buffer_proxy.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "ppapi/c/pp_completion_callback.h" | 11 #include "ppapi/c/pp_completion_callback.h" |
12 #include "ppapi/c/pp_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
13 #include "ppapi/c/dev/ppb_buffer_dev.h" | 13 #include "ppapi/c/dev/ppb_buffer_dev.h" |
14 #include "ppapi/proxy/plugin_dispatcher.h" | 14 #include "ppapi/proxy/plugin_dispatcher.h" |
15 #include "ppapi/proxy/plugin_resource.h" | 15 #include "ppapi/proxy/plugin_resource.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
17 | 17 |
18 namespace pp { | 18 namespace pp { |
19 namespace proxy { | 19 namespace proxy { |
20 | 20 |
21 class Buffer : public PluginResource { | 21 class Buffer : public PluginResource { |
22 public: | 22 public: |
23 Buffer(int memory_handle, uint32_t size); | 23 Buffer(PP_Instance instance, int memory_handle, uint32_t size); |
24 virtual ~Buffer(); | 24 virtual ~Buffer(); |
25 | 25 |
26 // Resource overrides. | 26 // Resource overrides. |
27 virtual Buffer* AsBuffer() { return this; } | 27 virtual Buffer* AsBuffer() { return this; } |
28 | 28 |
29 uint32_t size() const { return size_; } | 29 uint32_t size() const { return size_; } |
30 | 30 |
31 void* Map(); | 31 void* Map(); |
32 void Unmap(); | 32 void Unmap(); |
33 | 33 |
34 private: | 34 private: |
35 int memory_handle_; | 35 int memory_handle_; |
36 uint32_t size_; | 36 uint32_t size_; |
37 | 37 |
38 void* mapped_data_; | 38 void* mapped_data_; |
39 | 39 |
40 DISALLOW_COPY_AND_ASSIGN(Buffer); | 40 DISALLOW_COPY_AND_ASSIGN(Buffer); |
41 }; | 41 }; |
42 | 42 |
43 Buffer::Buffer(int memory_handle, uint32_t size) | 43 Buffer::Buffer(PP_Instance instance, int memory_handle, uint32_t size) |
44 : memory_handle_(memory_handle), | 44 : PluginResource(instance), |
| 45 memory_handle_(memory_handle), |
45 size_(size), | 46 size_(size), |
46 mapped_data_(NULL) { | 47 mapped_data_(NULL) { |
47 } | 48 } |
48 | 49 |
49 Buffer::~Buffer() { | 50 Buffer::~Buffer() { |
50 Unmap(); | 51 Unmap(); |
51 } | 52 } |
52 | 53 |
53 void* Buffer::Map() { | 54 void* Buffer::Map() { |
54 // TODO(brettw) implement this. | 55 // TODO(brettw) implement this. |
55 return mapped_data_; | 56 return mapped_data_; |
56 } | 57 } |
57 | 58 |
58 void Buffer::Unmap() { | 59 void Buffer::Unmap() { |
59 // TODO(brettw) implement this. | 60 // TODO(brettw) implement this. |
60 } | 61 } |
61 | 62 |
62 namespace { | 63 namespace { |
63 | 64 |
64 PP_Resource Create(PP_Instance instance, uint32_t size) { | 65 PP_Resource Create(PP_Instance instance, uint32_t size) { |
65 PP_Resource result = 0; | 66 PP_Resource result = 0; |
66 int32_t shm_handle = -1; | 67 int32_t shm_handle = -1; |
67 PluginDispatcher::Get()->Send( | 68 PluginDispatcher::GetForInstance(instance)->Send( |
68 new PpapiHostMsg_PPBBuffer_Create( | 69 new PpapiHostMsg_PPBBuffer_Create( |
69 INTERFACE_ID_PPB_BUFFER, instance, size, | 70 INTERFACE_ID_PPB_BUFFER, instance, size, |
70 &result, &shm_handle)); | 71 &result, &shm_handle)); |
71 if (!result) | 72 if (!result) |
72 return 0; | 73 return 0; |
73 | 74 |
74 linked_ptr<Buffer> object(new Buffer(static_cast<int>(shm_handle), size)); | 75 linked_ptr<Buffer> object(new Buffer(instance, static_cast<int>(shm_handle), |
75 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource( | 76 size)); |
76 result, object); | 77 PluginResourceTracker::GetInstance()->AddResource(result, object); |
77 return result; | 78 return result; |
78 } | 79 } |
79 | 80 |
80 PP_Bool IsBuffer(PP_Resource resource) { | 81 PP_Bool IsBuffer(PP_Resource resource) { |
81 Buffer* object = PluginResource::GetAs<Buffer>(resource); | 82 Buffer* object = PluginResource::GetAs<Buffer>(resource); |
82 return BoolToPPBool(!!object); | 83 return BoolToPPBool(!!object); |
83 } | 84 } |
84 | 85 |
85 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { | 86 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { |
86 Buffer* object = PluginResource::GetAs<Buffer>(resource); | 87 Buffer* object = PluginResource::GetAs<Buffer>(resource); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 uint32_t size, | 146 uint32_t size, |
146 PP_Resource* result_resource, | 147 PP_Resource* result_resource, |
147 int* result_shm_handle) { | 148 int* result_shm_handle) { |
148 *result_resource = ppb_buffer_target()->Create(instance, size); | 149 *result_resource = ppb_buffer_target()->Create(instance, size); |
149 // TODO(brettw) set the shm handle from a trusted interface. | 150 // TODO(brettw) set the shm handle from a trusted interface. |
150 *result_shm_handle = 0; | 151 *result_shm_handle = 0; |
151 } | 152 } |
152 | 153 |
153 } // namespace proxy | 154 } // namespace proxy |
154 } // namespace pp | 155 } // namespace pp |
OLD | NEW |