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" | |
8 #include "ppapi/shared_impl/host_resource.h" | 7 #include "ppapi/shared_impl/host_resource.h" |
9 #include "ppapi/shared_impl/ppapi_globals.h" | 8 #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" | 9 #include "ppapi/shared_impl/resource_tracker.h" |
12 #include "ppapi/shared_impl/var.h" | 10 #include "ppapi/shared_impl/var.h" |
13 | 11 |
14 using ppapi::thunk::PPB_DeviceRef_API; | 12 using ppapi::thunk::PPB_DeviceRef_API; |
15 | 13 |
16 namespace ppapi { | 14 namespace ppapi { |
17 | 15 |
18 DeviceRefData::DeviceRefData() | 16 DeviceRefData::DeviceRefData() |
19 : type(PP_DEVICETYPE_DEV_INVALID) { | 17 : type(PP_DEVICETYPE_DEV_INVALID) { |
20 } | 18 } |
(...skipping 14 matching lines...) Expand all Loading... |
35 } | 33 } |
36 | 34 |
37 PP_DeviceType_Dev PPB_DeviceRef_Shared::GetType() { | 35 PP_DeviceType_Dev PPB_DeviceRef_Shared::GetType() { |
38 return data_.type; | 36 return data_.type; |
39 } | 37 } |
40 | 38 |
41 PP_Var PPB_DeviceRef_Shared::GetName() { | 39 PP_Var PPB_DeviceRef_Shared::GetName() { |
42 return StringVar::StringToPPVar(data_.name); | 40 return StringVar::StringToPPVar(data_.name); |
43 } | 41 } |
44 | 42 |
45 // static | |
46 PP_Resource PPB_DeviceRef_Shared::CreateResourceArray( | |
47 ResourceObjectType type, | |
48 PP_Instance instance, | |
49 const std::vector<DeviceRefData>& devices) { | |
50 scoped_ptr<PP_Resource[]> elements; | |
51 size_t size = devices.size(); | |
52 if (size > 0) { | |
53 elements.reset(new PP_Resource[size]); | |
54 for (size_t index = 0; index < size; ++index) { | |
55 PPB_DeviceRef_Shared* device_object = | |
56 new PPB_DeviceRef_Shared(type, instance, devices[index]); | |
57 elements[index] = device_object->GetReference(); | |
58 } | |
59 } | |
60 PPB_ResourceArray_Shared* array_object = | |
61 new PPB_ResourceArray_Shared(type, instance, elements.get(), | |
62 static_cast<uint32_t>(size)); | |
63 | |
64 for (size_t index = 0; index < size; ++index) | |
65 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(elements[index]); | |
66 | |
67 return array_object->GetReference(); | |
68 } | |
69 | |
70 } // namespace ppapi | 43 } // namespace ppapi |
OLD | NEW |