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