OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/plugin_array_buffer_var.h" | 5 #include "ppapi/proxy/plugin_array_buffer_var.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
11 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
12 #include "ppapi/c/dev/ppb_buffer_dev.h" | 12 #include "ppapi/c/dev/ppb_buffer_dev.h" |
13 #include "ppapi/proxy/plugin_dispatcher.h" | 13 #include "ppapi/proxy/plugin_dispatcher.h" |
14 #include "ppapi/proxy/plugin_globals.h" | 14 #include "ppapi/proxy/plugin_globals.h" |
15 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
16 #include "ppapi/proxy/serialized_structs.h" | 16 #include "ppapi/proxy/serialized_structs.h" |
17 #include "ppapi/shared_impl/host_resource.h" | 17 #include "ppapi/shared_impl/host_resource.h" |
18 #include "ppapi/shared_impl/resource.h" | 18 #include "ppapi/shared_impl/resource.h" |
19 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
20 #include "ppapi/thunk/ppb_buffer_api.h" | 20 #include "ppapi/thunk/ppb_buffer_api.h" |
21 | 21 |
22 using base::SharedMemory; | 22 using base::SharedMemory; |
23 using base::SharedMemoryHandle; | 23 using base::SharedMemoryHandle; |
24 using ppapi::proxy::PluginGlobals; | 24 using ppapi::proxy::PluginGlobals; |
25 using ppapi::proxy::PluginResourceTracker; | 25 using ppapi::proxy::PluginResourceTracker; |
26 | 26 |
27 namespace ppapi { | 27 namespace ppapi { |
28 | 28 |
29 PluginArrayBufferVar::PluginArrayBufferVar(uint32 size_in_bytes) | 29 PluginArrayBufferVar::PluginArrayBufferVar(uint32_t size_in_bytes) |
30 : buffer_(size_in_bytes), | 30 : buffer_(size_in_bytes), |
31 plugin_handle_(base::SharedMemory::NULLHandle()), | 31 plugin_handle_(base::SharedMemory::NULLHandle()), |
32 size_in_bytes_(size_in_bytes) { | 32 size_in_bytes_(size_in_bytes) {} |
33 } | |
34 | 33 |
35 PluginArrayBufferVar::PluginArrayBufferVar(uint32 size_in_bytes, | 34 PluginArrayBufferVar::PluginArrayBufferVar(uint32_t size_in_bytes, |
36 SharedMemoryHandle plugin_handle) | 35 SharedMemoryHandle plugin_handle) |
37 : plugin_handle_(plugin_handle), | 36 : plugin_handle_(plugin_handle), size_in_bytes_(size_in_bytes) {} |
38 size_in_bytes_(size_in_bytes) { | |
39 } | |
40 | 37 |
41 PluginArrayBufferVar::~PluginArrayBufferVar() { | 38 PluginArrayBufferVar::~PluginArrayBufferVar() { |
42 Unmap(); | 39 Unmap(); |
43 | 40 |
44 if (shmem_.get() == NULL) { | 41 if (shmem_.get() == NULL) { |
45 // The SharedMemory destuctor can't close the handle for us. | 42 // The SharedMemory destuctor can't close the handle for us. |
46 if (SharedMemory::IsHandleValid(plugin_handle_)) | 43 if (SharedMemory::IsHandleValid(plugin_handle_)) |
47 SharedMemory::CloseHandle(plugin_handle_); | 44 SharedMemory::CloseHandle(plugin_handle_); |
48 } else { | 45 } else { |
49 // Delete SharedMemory, if we have one. | 46 // Delete SharedMemory, if we have one. |
(...skipping 15 matching lines...) Expand all Loading... |
65 if (buffer_.empty()) | 62 if (buffer_.empty()) |
66 return NULL; | 63 return NULL; |
67 return &(buffer_[0]); | 64 return &(buffer_[0]); |
68 } | 65 } |
69 | 66 |
70 void PluginArrayBufferVar::Unmap() { | 67 void PluginArrayBufferVar::Unmap() { |
71 if (shmem_.get()) | 68 if (shmem_.get()) |
72 shmem_->Unmap(); | 69 shmem_->Unmap(); |
73 } | 70 } |
74 | 71 |
75 uint32 PluginArrayBufferVar::ByteLength() { | 72 uint32_t PluginArrayBufferVar::ByteLength() { |
76 return size_in_bytes_; | 73 return size_in_bytes_; |
77 } | 74 } |
78 | 75 |
79 bool PluginArrayBufferVar::CopyToNewShmem( | 76 bool PluginArrayBufferVar::CopyToNewShmem( |
80 PP_Instance instance, | 77 PP_Instance instance, |
81 int* host_handle_id, | 78 int* host_handle_id, |
82 SharedMemoryHandle* plugin_out_handle) { | 79 SharedMemoryHandle* plugin_out_handle) { |
83 ppapi::proxy::PluginDispatcher* dispatcher = | 80 ppapi::proxy::PluginDispatcher* dispatcher = |
84 ppapi::proxy::PluginDispatcher::GetForInstance(instance); | 81 ppapi::proxy::PluginDispatcher::GetForInstance(instance); |
85 if (!dispatcher) | 82 if (!dispatcher) |
(...skipping 15 matching lines...) Expand all Loading... |
101 | 98 |
102 // We don't need to keep the shared memory around on the plugin side; | 99 // We don't need to keep the shared memory around on the plugin side; |
103 // we've already copied all our data into it. We'll make it invalid | 100 // we've already copied all our data into it. We'll make it invalid |
104 // just to be safe. | 101 // just to be safe. |
105 *plugin_out_handle = base::SharedMemory::NULLHandle(); | 102 *plugin_out_handle = base::SharedMemory::NULLHandle(); |
106 | 103 |
107 return true; | 104 return true; |
108 } | 105 } |
109 | 106 |
110 } // namespace ppapi | 107 } // namespace ppapi |
OLD | NEW |