Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/shared_impl/array_writer.h" | |
| 6 | |
| 7 #include "ppapi/shared_impl/ppapi_globals.h" | |
| 8 #include "ppapi/shared_impl/resource.h" | |
| 9 #include "ppapi/shared_impl/resource_tracker.h" | |
| 10 | |
| 11 namespace ppapi { | |
| 12 | |
| 13 ArrayWriter::ArrayWriter() { | |
| 14 Reset(); | |
| 15 } | |
| 16 | |
| 17 ArrayWriter::ArrayWriter(const PP_ArrayOutput& output) | |
| 18 : pp_array_output_(output) { | |
| 19 } | |
| 20 | |
| 21 ArrayWriter::~ArrayWriter() { | |
| 22 } | |
| 23 | |
| 24 void ArrayWriter::Reset() { | |
| 25 pp_array_output_.GetDataBuffer = NULL; | |
| 26 pp_array_output_.user_data = NULL; | |
| 27 } | |
| 28 | |
| 29 bool ArrayWriter::StoreResourceVector( | |
| 30 const std::vector< scoped_refptr<Resource> >& input) { | |
| 31 // Always call the alloc function, even on 0 array size. | |
| 32 void* dest = pp_array_output_.GetDataBuffer( | |
| 33 pp_array_output_.user_data, | |
| 34 static_cast<uint32_t>(input.size()), | |
| 35 sizeof(PP_Resource)); | |
| 36 | |
| 37 // Regardless of success, we clear the output to prevent future calls on | |
| 38 // this same output object. | |
| 39 Reset(); | |
| 40 | |
| 41 if (input.empty()) | |
| 42 return true; // Allow plugin to return NULL on 0 elements. | |
| 43 if (!dest) | |
| 44 return false; | |
| 45 | |
| 46 // Convert to PP_Resources. | |
| 47 PP_Resource* dest_resources = static_cast<PP_Resource*>(dest); | |
| 48 for (size_t i = 0; i < input.size(); i++) | |
| 49 dest_resources[i] = input[i]->GetReference(); | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 bool ArrayWriter::StoreResourceVector(const std::vector<PP_Resource>& input) { | |
| 54 // Always call the alloc function, even on 0 array size. | |
| 55 void* dest = pp_array_output_.GetDataBuffer( | |
| 56 pp_array_output_.user_data, | |
| 57 static_cast<uint32_t>(input.size()), | |
| 58 sizeof(PP_Resource)); | |
| 59 | |
| 60 // Regardless of success, we clear the output to prevent future calls on | |
| 61 // this same output object. | |
| 62 Reset(); | |
| 63 | |
| 64 if (input.empty()) | |
| 65 return true; // Allow plugin to return NULL on 0 elements. | |
| 66 if (!dest) { | |
| 67 // Free the resources. | |
| 68 for (size_t i = 0; i < input.size(); i++) | |
| 69 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(input[i]); | |
| 70 return false; | |
| 71 } | |
| 72 | |
| 73 std::copy(input.begin(), input.end(), static_cast<PP_Resource*>(dest)); | |
|
viettrungluu
2012/03/26 16:55:19
You need to include <algorithm>.
| |
| 74 return true; | |
| 75 } | |
| 76 | |
| 77 } // namespace ppapi | |
| OLD | NEW |