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 #include "webkit/plugins/ppapi/resource_helper.h" |
16 | 17 |
17 using ::ppapi::thunk::PPB_Buffer_API; | 18 using ::ppapi::thunk::PPB_Buffer_API; |
18 using ::ppapi::thunk::PPB_BufferTrusted_API; | 19 using ::ppapi::thunk::PPB_BufferTrusted_API; |
19 | 20 |
20 namespace webkit { | 21 namespace webkit { |
21 namespace ppapi { | 22 namespace ppapi { |
22 | 23 |
23 PPB_Buffer_Impl::PPB_Buffer_Impl(PluginInstance* instance) | 24 PPB_Buffer_Impl::PPB_Buffer_Impl(PP_Instance instance) |
24 : Resource(instance), size_(0), map_count_(0) { | 25 : Resource(instance), |
| 26 size_(0), |
| 27 map_count_(0) { |
25 } | 28 } |
26 | 29 |
27 PPB_Buffer_Impl::~PPB_Buffer_Impl() { | 30 PPB_Buffer_Impl::~PPB_Buffer_Impl() { |
28 } | 31 } |
29 | 32 |
30 // static | 33 // static |
31 PP_Resource PPB_Buffer_Impl::Create(PluginInstance* instance, uint32_t size) { | 34 PP_Resource PPB_Buffer_Impl::Create(PP_Instance instance, uint32_t size) { |
32 scoped_refptr<PPB_Buffer_Impl> buffer(new PPB_Buffer_Impl(instance)); | 35 scoped_refptr<PPB_Buffer_Impl> buffer(new PPB_Buffer_Impl(instance)); |
33 if (!buffer->Init(size)) | 36 if (!buffer->Init(size)) |
34 return 0; | 37 return 0; |
35 return buffer->GetReference(); | 38 return buffer->GetReference(); |
36 } | 39 } |
37 | 40 |
38 PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { | 41 PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { |
39 return this; | 42 return this; |
40 } | 43 } |
41 | 44 |
42 PPB_Buffer_API* PPB_Buffer_Impl::AsPPB_Buffer_API() { | 45 PPB_Buffer_API* PPB_Buffer_Impl::AsPPB_Buffer_API() { |
43 return this; | 46 return this; |
44 } | 47 } |
45 | 48 |
46 PPB_BufferTrusted_API* PPB_Buffer_Impl::AsPPB_BufferTrusted_API() { | 49 PPB_BufferTrusted_API* PPB_Buffer_Impl::AsPPB_BufferTrusted_API() { |
47 return this; | 50 return this; |
48 } | 51 } |
49 | 52 |
50 bool PPB_Buffer_Impl::Init(uint32_t size) { | 53 bool PPB_Buffer_Impl::Init(uint32_t size) { |
51 if (size == 0 || !instance()) | 54 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 55 if (size == 0 || !plugin_delegate) |
52 return false; | 56 return false; |
53 size_ = size; | 57 size_ = size; |
54 shared_memory_.reset( | 58 shared_memory_.reset(plugin_delegate->CreateAnonymousSharedMemory(size)); |
55 instance()->delegate()->CreateAnonymousSharedMemory(size)); | |
56 return shared_memory_.get() != NULL; | 59 return shared_memory_.get() != NULL; |
57 } | 60 } |
58 | 61 |
59 PP_Bool PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) { | 62 PP_Bool PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) { |
60 *size_in_bytes = size_; | 63 *size_in_bytes = size_; |
61 return PP_TRUE; | 64 return PP_TRUE; |
62 } | 65 } |
63 | 66 |
64 PP_Bool PPB_Buffer_Impl::IsMapped() { | 67 PP_Bool PPB_Buffer_Impl::IsMapped() { |
65 return PP_FromBool(!!shared_memory_->memory()); | 68 return PP_FromBool(!!shared_memory_->memory()); |
(...skipping 30 matching lines...) Expand all Loading... |
96 api->Describe(&size_); | 99 api->Describe(&size_); |
97 } | 100 } |
98 | 101 |
99 BufferAutoMapper::~BufferAutoMapper() { | 102 BufferAutoMapper::~BufferAutoMapper() { |
100 if (needs_unmap_) | 103 if (needs_unmap_) |
101 api_->Unmap(); | 104 api_->Unmap(); |
102 } | 105 } |
103 | 106 |
104 } // namespace ppapi | 107 } // namespace ppapi |
105 } // namespace webkit | 108 } // namespace webkit |
OLD | NEW |