OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_buffer_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "ppapi/c/dev/ppb_buffer_dev.h" | 11 #include "ppapi/c/dev/ppb_buffer_dev.h" |
12 #include "ppapi/c/pp_instance.h" | 12 #include "ppapi/c/pp_instance.h" |
13 #include "ppapi/c/pp_resource.h" | 13 #include "ppapi/c/pp_resource.h" |
14 #include "webkit/plugins/ppapi/common.h" | 14 #include "webkit/plugins/ppapi/common.h" |
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
16 | 16 |
17 using ::ppapi::thunk::PPB_Buffer_API; | 17 using ::ppapi::thunk::PPB_Buffer_API; |
| 18 using ::ppapi::thunk::PPB_BufferTrusted_API; |
18 | 19 |
19 namespace webkit { | 20 namespace webkit { |
20 namespace ppapi { | 21 namespace ppapi { |
21 | 22 |
22 PPB_Buffer_Impl::PPB_Buffer_Impl(PluginInstance* instance) | 23 PPB_Buffer_Impl::PPB_Buffer_Impl(PluginInstance* instance) |
23 : Resource(instance), size_(0) { | 24 : Resource(instance), size_(0) { |
24 } | 25 } |
25 | 26 |
26 PPB_Buffer_Impl::~PPB_Buffer_Impl() { | 27 PPB_Buffer_Impl::~PPB_Buffer_Impl() { |
27 } | 28 } |
(...skipping 10 matching lines...) Expand all Loading... |
38 } | 39 } |
39 | 40 |
40 PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { | 41 PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { |
41 return this; | 42 return this; |
42 } | 43 } |
43 | 44 |
44 PPB_Buffer_API* PPB_Buffer_Impl::AsPPB_Buffer_API() { | 45 PPB_Buffer_API* PPB_Buffer_Impl::AsPPB_Buffer_API() { |
45 return this; | 46 return this; |
46 } | 47 } |
47 | 48 |
| 49 PPB_BufferTrusted_API* PPB_Buffer_Impl::AsPPB_BufferTrusted_API() { |
| 50 return this; |
| 51 } |
| 52 |
48 bool PPB_Buffer_Impl::Init(uint32_t size) { | 53 bool PPB_Buffer_Impl::Init(uint32_t size) { |
49 if (size == 0 || !instance()) | 54 if (size == 0 || !instance()) |
50 return false; | 55 return false; |
51 size_ = size; | 56 size_ = size; |
52 shared_memory_.reset( | 57 shared_memory_.reset( |
53 instance()->delegate()->CreateAnonymousSharedMemory(size)); | 58 instance()->delegate()->CreateAnonymousSharedMemory(size)); |
54 return shared_memory_.get() != NULL; | 59 return shared_memory_.get() != NULL; |
55 } | 60 } |
56 | 61 |
57 PP_Bool PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) { | 62 PP_Bool PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) { |
(...skipping 10 matching lines...) Expand all Loading... |
68 DCHECK(shared_memory_.get()); | 73 DCHECK(shared_memory_.get()); |
69 if (!shared_memory_->Map(size_)) | 74 if (!shared_memory_->Map(size_)) |
70 return NULL; | 75 return NULL; |
71 return shared_memory_->memory(); | 76 return shared_memory_->memory(); |
72 } | 77 } |
73 | 78 |
74 void PPB_Buffer_Impl::Unmap() { | 79 void PPB_Buffer_Impl::Unmap() { |
75 shared_memory_->Unmap(); | 80 shared_memory_->Unmap(); |
76 } | 81 } |
77 | 82 |
| 83 int32_t PPB_Buffer_Impl::GetSharedMemory(int* shm_handle) { |
| 84 #if defined(OS_POSIX) |
| 85 *shm_handle = shared_memory_->handle().fd; |
| 86 #elif defined(OS_WIN) |
| 87 *shm_handle = reinterpret_cast<int>( |
| 88 shared_memory_->handle()); |
| 89 #else |
| 90 #error "Platform not supported." |
| 91 #endif |
| 92 return PP_OK; |
| 93 } |
| 94 |
78 BufferAutoMapper::BufferAutoMapper(PPB_Buffer_API* api) : api_(api) { | 95 BufferAutoMapper::BufferAutoMapper(PPB_Buffer_API* api) : api_(api) { |
79 needs_unmap_ = !PP_ToBool(api->IsMapped()); | 96 needs_unmap_ = !PP_ToBool(api->IsMapped()); |
80 data_ = api->Map(); | 97 data_ = api->Map(); |
81 api->Describe(&size_); | 98 api->Describe(&size_); |
82 } | 99 } |
83 | 100 |
84 BufferAutoMapper::~BufferAutoMapper() { | 101 BufferAutoMapper::~BufferAutoMapper() { |
85 if (needs_unmap_) | 102 if (needs_unmap_) |
86 api_->Unmap(); | 103 api_->Unmap(); |
87 } | 104 } |
88 | 105 |
89 } // namespace ppapi | 106 } // namespace ppapi |
90 } // namespace webkit | 107 } // namespace webkit |
OLD | NEW |