| 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/glue/plugins/pepper_buffer.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 "third_party/ppapi/c/pp_instance.h" | 11 #include "third_party/ppapi/c/pp_instance.h" |
| 12 #include "third_party/ppapi/c/pp_module.h" | 12 #include "third_party/ppapi/c/pp_module.h" |
| 13 #include "third_party/ppapi/c/pp_resource.h" | 13 #include "third_party/ppapi/c/pp_resource.h" |
| 14 #include "third_party/ppapi/c/ppb_buffer.h" | 14 #include "third_party/ppapi/c/ppb_buffer.h" |
| 15 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 15 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
| 16 #include "webkit/glue/plugins/pepper_plugin_module.h" | 16 #include "webkit/glue/plugins/pepper_plugin_module.h" |
| 17 #include "webkit/glue/plugins/pepper_resource_tracker.h" | |
| 18 | 17 |
| 19 namespace pepper { | 18 namespace pepper { |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 PP_Resource Create(PP_Module module_id, int32_t size) { | 22 PP_Resource Create(PP_Module module_id, int32_t size) { |
| 24 PluginModule* module = PluginModule::FromPPModule(module_id); | 23 PluginModule* module = PluginModule::FromPPModule(module_id); |
| 25 if (!module) | 24 if (!module) |
| 26 return NULL; | 25 return NULL; |
| 27 | 26 |
| 28 scoped_refptr<Buffer> buffer(new Buffer(module)); | 27 scoped_refptr<Buffer> buffer(new Buffer(module)); |
| 29 if (!buffer->Init(size)) | 28 if (!buffer->Init(size)) |
| 30 return NULL; | 29 return NULL; |
| 31 buffer->AddRef(); // AddRef for the caller. | 30 buffer->AddRef(); // AddRef for the caller. |
| 32 | 31 |
| 33 return buffer->GetResource(); | 32 return buffer->GetResource(); |
| 34 } | 33 } |
| 35 | 34 |
| 36 bool IsBuffer(PP_Resource resource) { | 35 bool IsBuffer(PP_Resource resource) { |
| 37 return !!ResourceTracker::Get()->GetAsBuffer(resource).get(); | 36 return !!Resource::GetAs<Buffer>(resource).get(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 bool Describe(PP_Resource resource, int32_t* size_in_bytes) { | 39 bool Describe(PP_Resource resource, int32_t* size_in_bytes) { |
| 41 scoped_refptr<Buffer> buffer( | 40 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); |
| 42 ResourceTracker::Get()->GetAsBuffer(resource)); | |
| 43 if (!buffer.get()) | 41 if (!buffer.get()) |
| 44 return false; | 42 return false; |
| 45 buffer->Describe(size_in_bytes); | 43 buffer->Describe(size_in_bytes); |
| 46 return true; | 44 return true; |
| 47 } | 45 } |
| 48 | 46 |
| 49 void* Map(PP_Resource resource) { | 47 void* Map(PP_Resource resource) { |
| 50 scoped_refptr<Buffer> buffer( | 48 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); |
| 51 ResourceTracker::Get()->GetAsBuffer(resource)); | |
| 52 if (!buffer.get()) | 49 if (!buffer.get()) |
| 53 return NULL; | 50 return NULL; |
| 54 return buffer->Map(); | 51 return buffer->Map(); |
| 55 } | 52 } |
| 56 | 53 |
| 57 void Unmap(PP_Resource resource) { | 54 void Unmap(PP_Resource resource) { |
| 58 scoped_refptr<Buffer> buffer( | 55 scoped_refptr<Buffer> buffer(Resource::GetAs<Buffer>(resource)); |
| 59 ResourceTracker::Get()->GetAsBuffer(resource)); | |
| 60 if (!buffer) | 56 if (!buffer) |
| 61 return; | 57 return; |
| 62 return buffer->Unmap(); | 58 return buffer->Unmap(); |
| 63 } | 59 } |
| 64 | 60 |
| 65 const PPB_Buffer ppb_buffer = { | 61 const PPB_Buffer ppb_buffer = { |
| 66 &Create, | 62 &Create, |
| 67 &IsBuffer, | 63 &IsBuffer, |
| 68 &Describe, | 64 &Describe, |
| 69 &Map, | 65 &Map, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 mem_buffer_.reset(); | 108 mem_buffer_.reset(); |
| 113 } | 109 } |
| 114 | 110 |
| 115 void Buffer::Swap(Buffer* other) { | 111 void Buffer::Swap(Buffer* other) { |
| 116 swap(other->mem_buffer_, mem_buffer_); | 112 swap(other->mem_buffer_, mem_buffer_); |
| 117 std::swap(other->size_, size_); | 113 std::swap(other->size_, size_); |
| 118 } | 114 } |
| 119 | 115 |
| 120 } // namespace pepper | 116 } // namespace pepper |
| 121 | 117 |
| OLD | NEW |