OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/shared_impl/ppb_device_ref_shared.h" | 5 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" |
7 #include "ppapi/shared_impl/host_resource.h" | 8 #include "ppapi/shared_impl/host_resource.h" |
| 9 #include "ppapi/shared_impl/ppapi_globals.h" |
| 10 #include "ppapi/shared_impl/ppb_resource_array_shared.h" |
| 11 #include "ppapi/shared_impl/resource_tracker.h" |
8 #include "ppapi/shared_impl/var.h" | 12 #include "ppapi/shared_impl/var.h" |
9 | 13 |
10 using ppapi::thunk::PPB_DeviceRef_API; | 14 using ppapi::thunk::PPB_DeviceRef_API; |
11 | 15 |
12 namespace ppapi { | 16 namespace ppapi { |
13 | 17 |
14 DeviceRefData::DeviceRefData() | 18 DeviceRefData::DeviceRefData() |
15 : type(PP_DEVICETYPE_DEV_INVALID) { | 19 : type(PP_DEVICETYPE_DEV_INVALID) { |
16 } | 20 } |
17 | 21 |
(...skipping 20 matching lines...) Expand all Loading... |
38 } | 42 } |
39 | 43 |
40 PP_DeviceType_Dev PPB_DeviceRef_Shared::GetType() { | 44 PP_DeviceType_Dev PPB_DeviceRef_Shared::GetType() { |
41 return data_.type; | 45 return data_.type; |
42 } | 46 } |
43 | 47 |
44 PP_Var PPB_DeviceRef_Shared::GetName() { | 48 PP_Var PPB_DeviceRef_Shared::GetName() { |
45 return StringVar::StringToPPVar(data_.name); | 49 return StringVar::StringToPPVar(data_.name); |
46 } | 50 } |
47 | 51 |
| 52 // static |
| 53 PP_Resource PPB_DeviceRef_Shared::CreateResourceArray( |
| 54 bool init_as_impl, |
| 55 PP_Instance instance, |
| 56 const std::vector<DeviceRefData>& devices) { |
| 57 scoped_array<PP_Resource> elements; |
| 58 size_t size = devices.size(); |
| 59 if (size > 0) { |
| 60 elements.reset(new PP_Resource[size]); |
| 61 for (size_t index = 0; index < size; ++index) { |
| 62 PPB_DeviceRef_Shared* device_object = init_as_impl ? |
| 63 new PPB_DeviceRef_Shared(InitAsImpl(), instance, devices[index]): |
| 64 new PPB_DeviceRef_Shared(InitAsProxy(), instance, devices[index]); |
| 65 elements[index] = device_object->GetReference(); |
| 66 } |
| 67 } |
| 68 PPB_ResourceArray_Shared* array_object = init_as_impl ? |
| 69 new PPB_ResourceArray_Shared(PPB_ResourceArray_Shared::InitAsImpl(), |
| 70 instance, elements.get(), size) : |
| 71 new PPB_ResourceArray_Shared(PPB_ResourceArray_Shared::InitAsProxy(), |
| 72 instance, elements.get(), size); |
| 73 |
| 74 for (size_t index = 0; index < size; ++index) |
| 75 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(elements[index]); |
| 76 |
| 77 return array_object->GetReference(); |
| 78 } |
| 79 |
48 } // namespace ppapi | 80 } // namespace ppapi |
OLD | NEW |