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 "webkit/glue/plugins/pepper_buffer.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/scoped_ptr.h" | 10 #include "base/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_module.h" | 13 #include "ppapi/c/pp_module.h" |
14 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
15 #include "webkit/glue/plugins/pepper_common.h" | 15 #include "webkit/plugins/ppapi/common.h" |
16 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 16 #include "webkit/plugins/ppapi/plugin_instance.h" |
17 #include "webkit/glue/plugins/pepper_plugin_module.h" | 17 #include "webkit/plugins/ppapi/plugin_module.h" |
18 | 18 |
19 namespace pepper { | 19 namespace webkit { |
| 20 namespace plugins { |
| 21 namespace ppapi { |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 PP_Resource Create(PP_Module module_id, uint32_t size) { | 25 PP_Resource Create(PP_Module module_id, uint32_t size) { |
24 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); | 26 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); |
25 if (!module) | 27 if (!module) |
26 return 0; | 28 return 0; |
27 | 29 |
28 scoped_refptr<Buffer> buffer(new Buffer(module)); | 30 scoped_refptr<PPB_Buffer_Impl> buffer(new PPB_Buffer_Impl(module)); |
29 if (!buffer->Init(size)) | 31 if (!buffer->Init(size)) |
30 return 0; | 32 return 0; |
31 | 33 |
32 return buffer->GetReference(); | 34 return buffer->GetReference(); |
33 } | 35 } |
34 | 36 |
35 PP_Bool IsBuffer(PP_Resource resource) { | 37 PP_Bool IsPPB_Buffer_Impl(PP_Resource resource) { |
36 return BoolToPPBool(!!Resource::GetAs<Buffer>(resource)); | 38 return BoolToPPBool(!!Resource::GetAs<PPB_Buffer_Impl>(resource)); |
37 } | 39 } |
38 | 40 |
39 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { | 41 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { |
40 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); | 42 scoped_refptr<PPB_Buffer_Impl> buffer( |
| 43 Resource::GetAs<PPB_Buffer_Impl>(resource)); |
41 if (!buffer) | 44 if (!buffer) |
42 return PP_FALSE; | 45 return PP_FALSE; |
43 buffer->Describe(size_in_bytes); | 46 buffer->Describe(size_in_bytes); |
44 return PP_TRUE; | 47 return PP_TRUE; |
45 } | 48 } |
46 | 49 |
47 void* Map(PP_Resource resource) { | 50 void* Map(PP_Resource resource) { |
48 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); | 51 scoped_refptr<PPB_Buffer_Impl> buffer( |
| 52 Resource::GetAs<PPB_Buffer_Impl>(resource)); |
49 if (!buffer) | 53 if (!buffer) |
50 return NULL; | 54 return NULL; |
51 return buffer->Map(); | 55 return buffer->Map(); |
52 } | 56 } |
53 | 57 |
54 void Unmap(PP_Resource resource) { | 58 void Unmap(PP_Resource resource) { |
55 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); | 59 scoped_refptr<PPB_Buffer_Impl> buffer( |
| 60 Resource::GetAs<PPB_Buffer_Impl>(resource)); |
56 if (!buffer) | 61 if (!buffer) |
57 return; | 62 return; |
58 return buffer->Unmap(); | 63 return buffer->Unmap(); |
59 } | 64 } |
60 | 65 |
61 const PPB_Buffer_Dev ppb_buffer = { | 66 const PPB_Buffer_Dev ppb_buffer = { |
62 &Create, | 67 &Create, |
63 &IsBuffer, | 68 &IsPPB_Buffer_Impl, |
64 &Describe, | 69 &Describe, |
65 &Map, | 70 &Map, |
66 &Unmap, | 71 &Unmap, |
67 }; | 72 }; |
68 | 73 |
69 } // namespace | 74 } // namespace |
70 | 75 |
71 Buffer::Buffer(PluginModule* module) | 76 PPB_Buffer_Impl::PPB_Buffer_Impl(PluginModule* module) |
72 : Resource(module), | 77 : Resource(module), |
73 size_(0) { | 78 size_(0) { |
74 } | 79 } |
75 | 80 |
76 Buffer::~Buffer() { | 81 PPB_Buffer_Impl::~PPB_Buffer_Impl() { |
77 } | 82 } |
78 | 83 |
79 // static | 84 // static |
80 const PPB_Buffer_Dev* Buffer::GetInterface() { | 85 const PPB_Buffer_Dev* PPB_Buffer_Impl::GetInterface() { |
81 return &ppb_buffer; | 86 return &ppb_buffer; |
82 } | 87 } |
83 | 88 |
84 Buffer* Buffer::AsBuffer() { return this; } | 89 PPB_Buffer_Impl* PPB_Buffer_Impl::AsPPB_Buffer_Impl() { |
| 90 return this; |
| 91 } |
85 | 92 |
86 bool Buffer::Init(uint32_t size) { | 93 bool PPB_Buffer_Impl::Init(uint32_t size) { |
87 if (size == 0) | 94 if (size == 0) |
88 return false; | 95 return false; |
89 Unmap(); | 96 Unmap(); |
90 size_ = size; | 97 size_ = size; |
91 return true; | 98 return true; |
92 } | 99 } |
93 | 100 |
94 void Buffer::Describe(uint32_t* size_in_bytes) const { | 101 void PPB_Buffer_Impl::Describe(uint32_t* size_in_bytes) const { |
95 *size_in_bytes = size_; | 102 *size_in_bytes = size_; |
96 } | 103 } |
97 | 104 |
98 void* Buffer::Map() { | 105 void* PPB_Buffer_Impl::Map() { |
99 if (size_ == 0) | 106 if (size_ == 0) |
100 return NULL; | 107 return NULL; |
101 | 108 |
102 if (!is_mapped()) { | 109 if (!is_mapped()) { |
103 mem_buffer_.reset(new unsigned char[size_]); | 110 mem_buffer_.reset(new unsigned char[size_]); |
104 memset(mem_buffer_.get(), 0, size_); | 111 memset(mem_buffer_.get(), 0, size_); |
105 } | 112 } |
106 return mem_buffer_.get(); | 113 return mem_buffer_.get(); |
107 } | 114 } |
108 | 115 |
109 void Buffer::Unmap() { | 116 void PPB_Buffer_Impl::Unmap() { |
110 mem_buffer_.reset(); | 117 mem_buffer_.reset(); |
111 } | 118 } |
112 | 119 |
113 void Buffer::Swap(Buffer* other) { | 120 } // namespace ppapi |
114 swap(other->mem_buffer_, mem_buffer_); | 121 } // namespace plugins |
115 std::swap(other->size_, size_); | 122 } // namespace webkit |
116 } | |
117 | 123 |
118 } // namespace pepper | |
119 | |
OLD | NEW |