[email protected] | e10b2b28a | 2012-03-14 23:17:14 | [diff] [blame] | 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/cpp/array_output.h" |
| 6 | |
| 7 | #include "ppapi/cpp/logging.h" |
| 8 | |
| 9 | namespace pp { |
| 10 | |
| 11 | // static |
| 12 | void* ArrayOutputAdapterBase::GetDataBufferThunk(void* user_data, |
| 13 | uint32_t element_count, |
| 14 | uint32_t element_size) { |
| 15 | return static_cast<ArrayOutputAdapterBase*>(user_data)-> |
| 16 | GetDataBuffer(element_count, element_size); |
| 17 | } |
| 18 | |
| 19 | VarArrayOutputAdapterWithStorage::VarArrayOutputAdapterWithStorage() |
| 20 | : ArrayOutputAdapter<PP_Var>() { |
| 21 | set_output(&temp_storage_); |
| 22 | } |
| 23 | |
[email protected] | 7ac673b | 2012-04-05 07:10:58 | [diff] [blame] | 24 | VarArrayOutputAdapterWithStorage::~VarArrayOutputAdapterWithStorage() { |
| 25 | if (!temp_storage_.empty()) { |
| 26 | // An easy way to release the var references held by this object. |
| 27 | output(); |
| 28 | } |
| 29 | } |
| 30 | |
[email protected] | e10b2b28a | 2012-03-14 23:17:14 | [diff] [blame] | 31 | std::vector<Var>& VarArrayOutputAdapterWithStorage::output() { |
| 32 | PP_DCHECK(output_storage_.empty()); |
| 33 | |
| 34 | output_storage_.reserve(temp_storage_.size()); |
| 35 | for (size_t i = 0; i < temp_storage_.size(); i++) |
| 36 | output_storage_.push_back(Var(PASS_REF, temp_storage_[i])); |
| 37 | temp_storage_.clear(); |
| 38 | return output_storage_; |
| 39 | } |
| 40 | |
| 41 | } // namespace pp |