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/array_writer.h" | 5 #include "ppapi/shared_impl/array_writer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
10 #include "ppapi/shared_impl/resource.h" | 10 #include "ppapi/shared_impl/resource.h" |
11 #include "ppapi/shared_impl/resource_tracker.h" | 11 #include "ppapi/shared_impl/resource_tracker.h" |
| 12 #include "ppapi/shared_impl/var.h" |
| 13 #include "ppapi/shared_impl/var_tracker.h" |
12 | 14 |
13 namespace ppapi { | 15 namespace ppapi { |
14 | 16 |
15 ArrayWriter::ArrayWriter() { | 17 ArrayWriter::ArrayWriter() { |
16 Reset(); | 18 Reset(); |
17 } | 19 } |
18 | 20 |
19 ArrayWriter::ArrayWriter(const PP_ArrayOutput& output) | 21 ArrayWriter::ArrayWriter(const PP_ArrayOutput& output) |
20 : pp_array_output_(output) { | 22 : pp_array_output_(output) { |
21 } | 23 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // Free the resources. | 71 // Free the resources. |
70 for (size_t i = 0; i < input.size(); i++) | 72 for (size_t i = 0; i < input.size(); i++) |
71 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(input[i]); | 73 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(input[i]); |
72 return false; | 74 return false; |
73 } | 75 } |
74 | 76 |
75 std::copy(input.begin(), input.end(), static_cast<PP_Resource*>(dest)); | 77 std::copy(input.begin(), input.end(), static_cast<PP_Resource*>(dest)); |
76 return true; | 78 return true; |
77 } | 79 } |
78 | 80 |
| 81 bool ArrayWriter::StoreVarVector( |
| 82 const std::vector< scoped_refptr<Var> >& input) { |
| 83 // Always call the alloc function, even on 0 array size. |
| 84 void* dest = pp_array_output_.GetDataBuffer( |
| 85 pp_array_output_.user_data, |
| 86 static_cast<uint32_t>(input.size()), |
| 87 sizeof(PP_Var)); |
| 88 |
| 89 // Regardless of success, we clear the output to prevent future calls on |
| 90 // this same output object. |
| 91 Reset(); |
| 92 |
| 93 if (input.empty()) |
| 94 return true; // Allow plugin to return NULL on 0 elements. |
| 95 if (!dest) |
| 96 return false; |
| 97 |
| 98 // Convert to PP_Vars. |
| 99 PP_Var* dest_vars = static_cast<PP_Var*>(dest); |
| 100 for (size_t i = 0; i < input.size(); i++) |
| 101 dest_vars[i] = input[i]->GetPPVar(); |
| 102 return true; |
| 103 } |
| 104 |
| 105 bool ArrayWriter::StoreVarVector(const std::vector<PP_Var>& input) { |
| 106 // Always call the alloc function, even on 0 array size. |
| 107 void* dest = pp_array_output_.GetDataBuffer( |
| 108 pp_array_output_.user_data, |
| 109 static_cast<uint32_t>(input.size()), |
| 110 sizeof(PP_Var)); |
| 111 |
| 112 // Regardless of success, we clear the output to prevent future calls on |
| 113 // this same output object. |
| 114 Reset(); |
| 115 |
| 116 if (input.empty()) |
| 117 return true; // Allow plugin to return NULL on 0 elements. |
| 118 if (!dest) { |
| 119 // Free the vars. |
| 120 for (size_t i = 0; i < input.size(); i++) |
| 121 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(input[i]); |
| 122 return false; |
| 123 } |
| 124 |
| 125 std::copy(input.begin(), input.end(), static_cast<PP_Var*>(dest)); |
| 126 return true; |
| 127 } |
| 128 |
79 } // namespace ppapi | 129 } // namespace ppapi |
OLD | NEW |