| 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 "base/android/jni_array.h" | 5 #include "base/android/jni_array.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 DCHECK(out); | 160 DCHECK(out); |
| 161 out->clear(); | 161 out->clear(); |
| 162 jsize len = env->GetArrayLength(int_array); | 162 jsize len = env->GetArrayLength(int_array); |
| 163 jint* ints = env->GetIntArrayElements(int_array, NULL); | 163 jint* ints = env->GetIntArrayElements(int_array, NULL); |
| 164 for (jsize i = 0; i < len; ++i) { | 164 for (jsize i = 0; i < len; ++i) { |
| 165 out->push_back(static_cast<int>(ints[i])); | 165 out->push_back(static_cast<int>(ints[i])); |
| 166 } | 166 } |
| 167 env->ReleaseIntArrayElements(int_array, ints, JNI_ABORT); | 167 env->ReleaseIntArrayElements(int_array, ints, JNI_ABORT); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void JavaLongArrayToLongVector(JNIEnv* env, |
| 171 jlongArray long_array, |
| 172 std::vector<long>* out) { |
| 173 DCHECK(out); |
| 174 out->clear(); |
| 175 jsize len = env->GetArrayLength(long_array); |
| 176 jlong* longs = env->GetLongArrayElements(long_array, NULL); |
| 177 for (jsize i = 0; i < len; ++i) { |
| 178 out->push_back(static_cast<long>(longs[i])); |
| 179 } |
| 180 env->ReleaseLongArrayElements(long_array, longs, JNI_ABORT); |
| 181 } |
| 182 |
| 170 void JavaFloatArrayToFloatVector(JNIEnv* env, | 183 void JavaFloatArrayToFloatVector(JNIEnv* env, |
| 171 jfloatArray float_array, | 184 jfloatArray float_array, |
| 172 std::vector<float>* out) { | 185 std::vector<float>* out) { |
| 173 DCHECK(out); | 186 DCHECK(out); |
| 174 out->clear(); | 187 out->clear(); |
| 175 jsize len = env->GetArrayLength(float_array); | 188 jsize len = env->GetArrayLength(float_array); |
| 176 jfloat* floats = env->GetFloatArrayElements(float_array, NULL); | 189 jfloat* floats = env->GetFloatArrayElements(float_array, NULL); |
| 177 for (jsize i = 0; i < len; ++i) { | 190 for (jsize i = 0; i < len; ++i) { |
| 178 out->push_back(static_cast<float>(floats[i])); | 191 out->push_back(static_cast<float>(floats[i])); |
| 179 } | 192 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 194 env->GetObjectArrayElement(array, i))); | 207 env->GetObjectArrayElement(array, i))); |
| 195 jsize bytes_len = env->GetArrayLength(bytes_array.obj()); | 208 jsize bytes_len = env->GetArrayLength(bytes_array.obj()); |
| 196 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), NULL); | 209 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), NULL); |
| 197 (*out)[i].assign(reinterpret_cast<const char*>(bytes), bytes_len); | 210 (*out)[i].assign(reinterpret_cast<const char*>(bytes), bytes_len); |
| 198 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT); | 211 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT); |
| 199 } | 212 } |
| 200 } | 213 } |
| 201 | 214 |
| 202 } // namespace android | 215 } // namespace android |
| 203 } // namespace base | 216 } // namespace base |
| OLD | NEW |