| 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(PP_Instance instance, int memory_handle, uint32_t size); | 23 Buffer(PP_Instance instance, |
| 24 SerializedResource resource, |
| 25 int memory_handle, |
| 26 uint32_t size); |
| 24 virtual ~Buffer(); | 27 virtual ~Buffer(); |
| 25 | 28 |
| 26 // Resource overrides. | 29 // Resource overrides. |
| 27 virtual Buffer* AsBuffer() { return this; } | 30 virtual Buffer* AsBuffer() { return this; } |
| 28 | 31 |
| 29 uint32_t size() const { return size_; } | 32 uint32_t size() const { return size_; } |
| 30 | 33 |
| 31 void* Map(); | 34 void* Map(); |
| 32 void Unmap(); | 35 void Unmap(); |
| 33 | 36 |
| 34 private: | 37 private: |
| 35 int memory_handle_; | 38 int memory_handle_; |
| 36 uint32_t size_; | 39 uint32_t size_; |
| 37 | 40 |
| 38 void* mapped_data_; | 41 void* mapped_data_; |
| 39 | 42 |
| 40 DISALLOW_COPY_AND_ASSIGN(Buffer); | 43 DISALLOW_COPY_AND_ASSIGN(Buffer); |
| 41 }; | 44 }; |
| 42 | 45 |
| 43 Buffer::Buffer(PP_Instance instance, int memory_handle, uint32_t size) | 46 Buffer::Buffer(PP_Instance instance, |
| 44 : PluginResource(instance), | 47 SerializedResource resource, |
| 48 int memory_handle, |
| 49 uint32_t size) |
| 50 : PluginResource(instance, resource), |
| 45 memory_handle_(memory_handle), | 51 memory_handle_(memory_handle), |
| 46 size_(size), | 52 size_(size), |
| 47 mapped_data_(NULL) { | 53 mapped_data_(NULL) { |
| 48 } | 54 } |
| 49 | 55 |
| 50 Buffer::~Buffer() { | 56 Buffer::~Buffer() { |
| 51 Unmap(); | 57 Unmap(); |
| 52 } | 58 } |
| 53 | 59 |
| 54 void* Buffer::Map() { | 60 void* Buffer::Map() { |
| 55 // TODO(brettw) implement this. | 61 // TODO(brettw) implement this. |
| 56 return mapped_data_; | 62 return mapped_data_; |
| 57 } | 63 } |
| 58 | 64 |
| 59 void Buffer::Unmap() { | 65 void Buffer::Unmap() { |
| 60 // TODO(brettw) implement this. | 66 // TODO(brettw) implement this. |
| 61 } | 67 } |
| 62 | 68 |
| 63 namespace { | 69 namespace { |
| 64 | 70 |
| 65 PP_Resource Create(PP_Instance instance, uint32_t size) { | 71 PP_Resource Create(PP_Instance instance, uint32_t size) { |
| 66 PP_Resource result = 0; | 72 SerializedResource result; |
| 67 int32_t shm_handle = -1; | 73 int32_t shm_handle = -1; |
| 68 PluginDispatcher::GetForInstance(instance)->Send( | 74 PluginDispatcher::GetForInstance(instance)->Send( |
| 69 new PpapiHostMsg_PPBBuffer_Create( | 75 new PpapiHostMsg_PPBBuffer_Create( |
| 70 INTERFACE_ID_PPB_BUFFER, instance, size, | 76 INTERFACE_ID_PPB_BUFFER, instance, size, |
| 71 &result, &shm_handle)); | 77 &result, &shm_handle)); |
| 72 if (!result) | 78 if (result.is_null()) |
| 73 return 0; | 79 return 0; |
| 74 | 80 |
| 75 linked_ptr<Buffer> object(new Buffer(instance, static_cast<int>(shm_handle), | 81 linked_ptr<Buffer> object(new Buffer(instance, result, |
| 76 size)); | 82 static_cast<int>(shm_handle), size)); |
| 77 PluginResourceTracker::GetInstance()->AddResource(result, object); | 83 return PluginResourceTracker::GetInstance()->AddResource(object); |
| 78 return result; | |
| 79 } | 84 } |
| 80 | 85 |
| 81 PP_Bool IsBuffer(PP_Resource resource) { | 86 PP_Bool IsBuffer(PP_Resource resource) { |
| 82 Buffer* object = PluginResource::GetAs<Buffer>(resource); | 87 Buffer* object = PluginResource::GetAs<Buffer>(resource); |
| 83 return BoolToPPBool(!!object); | 88 return BoolToPPBool(!!object); |
| 84 } | 89 } |
| 85 | 90 |
| 86 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { | 91 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { |
| 87 Buffer* object = PluginResource::GetAs<Buffer>(resource); | 92 Buffer* object = PluginResource::GetAs<Buffer>(resource); |
| 88 if (!object) { | 93 if (!object) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) | 142 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) |
| 138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate) | 143 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate) |
| 139 IPC_MESSAGE_UNHANDLED(handled = false) | 144 IPC_MESSAGE_UNHANDLED(handled = false) |
| 140 IPC_END_MESSAGE_MAP() | 145 IPC_END_MESSAGE_MAP() |
| 141 // TODO(brettw) handle bad messages! | 146 // TODO(brettw) handle bad messages! |
| 142 return handled; | 147 return handled; |
| 143 } | 148 } |
| 144 | 149 |
| 145 void PPB_Buffer_Proxy::OnMsgCreate(PP_Instance instance, | 150 void PPB_Buffer_Proxy::OnMsgCreate(PP_Instance instance, |
| 146 uint32_t size, | 151 uint32_t size, |
| 147 PP_Resource* result_resource, | 152 SerializedResource* result_resource, |
| 148 int* result_shm_handle) { | 153 int* result_shm_handle) { |
| 149 *result_resource = ppb_buffer_target()->Create(instance, size); | 154 result_resource->set_host_resource( |
| 155 ppb_buffer_target()->Create(instance, size)); |
| 150 // TODO(brettw) set the shm handle from a trusted interface. | 156 // TODO(brettw) set the shm handle from a trusted interface. |
| 151 *result_shm_handle = 0; | 157 *result_shm_handle = 0; |
| 152 } | 158 } |
| 153 | 159 |
| 154 } // namespace proxy | 160 } // namespace proxy |
| 155 } // namespace pp | 161 } // namespace pp |
| OLD | NEW |