OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/android/system/core_impl.h" | 5 #include "mojo/android/system/core_impl.h" |
6 | 6 |
7 #include "base/android/base_jni_registrar.h" | 7 #include "base/android/base_jni_registrar.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_registrar.h" | 9 #include "base/android/jni_registrar.h" |
10 #include "base/android/library_loader/library_loader_hooks.h" | 10 #include "base/android/library_loader/library_loader_hooks.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); | 137 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); |
138 DCHECK(buffer_start); | 138 DCHECK(buffer_start); |
139 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); | 139 DCHECK_EQ(reinterpret_cast<const uintptr_t>(buffer_start) % 8, 0u); |
140 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); | 140 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); |
141 DCHECK_EQ(buffer_size, sizeof(MojoCreateSharedBufferOptions)); | 141 DCHECK_EQ(buffer_size, sizeof(MojoCreateSharedBufferOptions)); |
142 options = static_cast<const MojoCreateSharedBufferOptions*>(buffer_start); | 142 options = static_cast<const MojoCreateSharedBufferOptions*>(buffer_start); |
143 DCHECK_EQ(options->struct_size, buffer_size); | 143 DCHECK_EQ(options->struct_size, buffer_size); |
144 } | 144 } |
145 MojoHandle handle; | 145 MojoHandle handle; |
146 MojoResult result = MojoCreateSharedBuffer(options, num_bytes, &handle); | 146 MojoResult result = MojoCreateSharedBuffer(options, num_bytes, &handle); |
147 return Java_CoreImpl_newNativeCreationResult(env, result, handle, 0) | 147 return Java_CoreImpl_newResultAndInteger(env, result, handle).Release(); |
148 .Release(); | |
149 } | 148 } |
150 | 149 |
151 static jint Close(JNIEnv* env, jobject jcaller, jint mojo_handle) { | 150 static jint Close(JNIEnv* env, jobject jcaller, jint mojo_handle) { |
152 return MojoClose(mojo_handle); | 151 return MojoClose(mojo_handle); |
153 } | 152 } |
154 | 153 |
155 static jint Wait(JNIEnv* env, | 154 static jint Wait(JNIEnv* env, |
156 jobject jcaller, | 155 jobject jcaller, |
157 jobject buffer, | 156 jobject buffer, |
158 jint mojo_handle, | 157 jint mojo_handle, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 static_cast<MojoHandle*>(env->GetDirectBufferAddress(handles_buffer)); | 215 static_cast<MojoHandle*>(env->GetDirectBufferAddress(handles_buffer)); |
217 num_handles = env->GetDirectBufferCapacity(handles_buffer) / 4; | 216 num_handles = env->GetDirectBufferCapacity(handles_buffer) / 4; |
218 } | 217 } |
219 MojoResult result = MojoReadMessage( | 218 MojoResult result = MojoReadMessage( |
220 mojo_handle, buffer_start, &buffer_size, handles, &num_handles, flags); | 219 mojo_handle, buffer_start, &buffer_size, handles, &num_handles, flags); |
221 // Jave code will handle taking ownership of any received handle. | 220 // Jave code will handle taking ownership of any received handle. |
222 return Java_CoreImpl_newReadMessageResult( | 221 return Java_CoreImpl_newReadMessageResult( |
223 env, result, buffer_size, num_handles).Release(); | 222 env, result, buffer_size, num_handles).Release(); |
224 } | 223 } |
225 | 224 |
226 static jint ReadData(JNIEnv* env, | 225 static jobject ReadData(JNIEnv* env, |
227 jobject jcaller, | 226 jobject jcaller, |
228 jint mojo_handle, | 227 jint mojo_handle, |
229 jobject elements, | 228 jobject elements, |
230 jint elements_capacity, | 229 jint elements_capacity, |
231 jint flags) { | 230 jint flags) { |
232 void* buffer_start = 0; | 231 void* buffer_start = 0; |
233 uint32_t buffer_size = elements_capacity; | 232 uint32_t buffer_size = elements_capacity; |
234 if (elements) { | 233 if (elements) { |
235 buffer_start = env->GetDirectBufferAddress(elements); | 234 buffer_start = env->GetDirectBufferAddress(elements); |
236 DCHECK(buffer_start); | 235 DCHECK(buffer_start); |
237 DCHECK(elements_capacity <= env->GetDirectBufferCapacity(elements)); | 236 DCHECK(elements_capacity <= env->GetDirectBufferCapacity(elements)); |
238 } | 237 } |
239 MojoResult result = | 238 MojoResult result = |
240 MojoReadData(mojo_handle, buffer_start, &buffer_size, flags); | 239 MojoReadData(mojo_handle, buffer_start, &buffer_size, flags); |
241 if (result < 0) { | 240 return Java_CoreImpl_newResultAndInteger( |
242 return result; | 241 env, result, (result == MOJO_RESULT_OK) ? buffer_size : 0) |
243 } | 242 .Release(); |
244 return buffer_size; | |
245 } | 243 } |
246 | 244 |
247 static jobject BeginReadData(JNIEnv* env, | 245 static jobject BeginReadData(JNIEnv* env, |
248 jobject jcaller, | 246 jobject jcaller, |
249 jint mojo_handle, | 247 jint mojo_handle, |
250 jint num_bytes, | 248 jint num_bytes, |
251 jint flags) { | 249 jint flags) { |
252 void const* buffer = 0; | 250 void const* buffer = 0; |
253 uint32_t buffer_size = num_bytes; | 251 uint32_t buffer_size = num_bytes; |
254 MojoResult result = | 252 MojoResult result = |
255 MojoBeginReadData(mojo_handle, &buffer, &buffer_size, flags); | 253 MojoBeginReadData(mojo_handle, &buffer, &buffer_size, flags); |
256 jobject byte_buffer = 0; | 254 jobject byte_buffer = 0; |
257 if (result == MOJO_RESULT_OK) { | 255 if (result == MOJO_RESULT_OK) { |
258 byte_buffer = | 256 byte_buffer = |
259 env->NewDirectByteBuffer(const_cast<void*>(buffer), buffer_size); | 257 env->NewDirectByteBuffer(const_cast<void*>(buffer), buffer_size); |
260 } | 258 } |
261 return Java_CoreImpl_newNativeCodeAndBufferResult(env, result, byte_buffer) | 259 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer).Release(); |
262 .Release(); | |
263 } | 260 } |
264 | 261 |
265 static jint EndReadData(JNIEnv* env, | 262 static jint EndReadData(JNIEnv* env, |
266 jobject jcaller, | 263 jobject jcaller, |
267 jint mojo_handle, | 264 jint mojo_handle, |
268 jint num_bytes_read) { | 265 jint num_bytes_read) { |
269 return MojoEndReadData(mojo_handle, num_bytes_read); | 266 return MojoEndReadData(mojo_handle, num_bytes_read); |
270 } | 267 } |
271 | 268 |
272 static jint WriteData(JNIEnv* env, | 269 static jobject WriteData(JNIEnv* env, |
273 jobject jcaller, | 270 jobject jcaller, |
274 jint mojo_handle, | 271 jint mojo_handle, |
275 jobject elements, | 272 jobject elements, |
276 jint limit, | 273 jint limit, |
277 jint flags) { | 274 jint flags) { |
278 void* buffer_start = env->GetDirectBufferAddress(elements); | 275 void* buffer_start = env->GetDirectBufferAddress(elements); |
279 DCHECK(buffer_start); | 276 DCHECK(buffer_start); |
280 DCHECK(limit <= env->GetDirectBufferCapacity(elements)); | 277 DCHECK(limit <= env->GetDirectBufferCapacity(elements)); |
281 uint32_t buffer_size = limit; | 278 uint32_t buffer_size = limit; |
282 MojoResult result = | 279 MojoResult result = |
283 MojoWriteData(mojo_handle, buffer_start, &buffer_size, flags); | 280 MojoWriteData(mojo_handle, buffer_start, &buffer_size, flags); |
284 if (result < 0) { | 281 return Java_CoreImpl_newResultAndInteger( |
285 return result; | 282 env, result, (result == MOJO_RESULT_OK) ? buffer_size : 0) |
286 } | 283 .Release(); |
287 return buffer_size; | |
288 } | 284 } |
289 | 285 |
290 static jobject BeginWriteData(JNIEnv* env, | 286 static jobject BeginWriteData(JNIEnv* env, |
291 jobject jcaller, | 287 jobject jcaller, |
292 jint mojo_handle, | 288 jint mojo_handle, |
293 jint num_bytes, | 289 jint num_bytes, |
294 jint flags) { | 290 jint flags) { |
295 void* buffer = 0; | 291 void* buffer = 0; |
296 uint32_t buffer_size = num_bytes; | 292 uint32_t buffer_size = num_bytes; |
297 MojoResult result = | 293 MojoResult result = |
298 MojoBeginWriteData(mojo_handle, &buffer, &buffer_size, flags); | 294 MojoBeginWriteData(mojo_handle, &buffer, &buffer_size, flags); |
299 jobject byte_buffer = 0; | 295 jobject byte_buffer = 0; |
300 if (result == MOJO_RESULT_OK) { | 296 if (result == MOJO_RESULT_OK) { |
301 byte_buffer = env->NewDirectByteBuffer(buffer, buffer_size); | 297 byte_buffer = env->NewDirectByteBuffer(buffer, buffer_size); |
302 } | 298 } |
303 return Java_CoreImpl_newNativeCodeAndBufferResult(env, result, byte_buffer) | 299 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer).Release(); |
304 .Release(); | |
305 } | 300 } |
306 | 301 |
307 static jint EndWriteData(JNIEnv* env, | 302 static jint EndWriteData(JNIEnv* env, |
308 jobject jcaller, | 303 jobject jcaller, |
309 jint mojo_handle, | 304 jint mojo_handle, |
310 jint num_bytes_written) { | 305 jint num_bytes_written) { |
311 return MojoEndWriteData(mojo_handle, num_bytes_written); | 306 return MojoEndWriteData(mojo_handle, num_bytes_written); |
312 } | 307 } |
313 | 308 |
314 static jobject Duplicate(JNIEnv* env, | 309 static jobject Duplicate(JNIEnv* env, |
315 jobject jcaller, | 310 jobject jcaller, |
316 jint mojo_handle, | 311 jint mojo_handle, |
317 jobject options_buffer) { | 312 jobject options_buffer) { |
318 const MojoDuplicateBufferHandleOptions* options = 0; | 313 const MojoDuplicateBufferHandleOptions* options = 0; |
319 if (options_buffer) { | 314 if (options_buffer) { |
320 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); | 315 const void* buffer_start = env->GetDirectBufferAddress(options_buffer); |
321 DCHECK(buffer_start); | 316 DCHECK(buffer_start); |
322 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); | 317 const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); |
323 DCHECK_EQ(buffer_size, sizeof(MojoDuplicateBufferHandleOptions)); | 318 DCHECK_EQ(buffer_size, sizeof(MojoDuplicateBufferHandleOptions)); |
324 options = | 319 options = |
325 static_cast<const MojoDuplicateBufferHandleOptions*>(buffer_start); | 320 static_cast<const MojoDuplicateBufferHandleOptions*>(buffer_start); |
326 DCHECK_EQ(options->struct_size, buffer_size); | 321 DCHECK_EQ(options->struct_size, buffer_size); |
327 } | 322 } |
328 MojoHandle handle; | 323 MojoHandle handle; |
329 MojoResult result = MojoDuplicateBufferHandle(mojo_handle, options, &handle); | 324 MojoResult result = MojoDuplicateBufferHandle(mojo_handle, options, &handle); |
330 return Java_CoreImpl_newNativeCreationResult(env, result, handle, 0) | 325 return Java_CoreImpl_newResultAndInteger(env, result, handle).Release(); |
331 .Release(); | |
332 } | 326 } |
333 | 327 |
334 static jobject Map(JNIEnv* env, | 328 static jobject Map(JNIEnv* env, |
335 jobject jcaller, | 329 jobject jcaller, |
336 jint mojo_handle, | 330 jint mojo_handle, |
337 jlong offset, | 331 jlong offset, |
338 jlong num_bytes, | 332 jlong num_bytes, |
339 jint flags) { | 333 jint flags) { |
340 void* buffer = 0; | 334 void* buffer = 0; |
341 MojoResult result = | 335 MojoResult result = |
342 MojoMapBuffer(mojo_handle, offset, num_bytes, &buffer, flags); | 336 MojoMapBuffer(mojo_handle, offset, num_bytes, &buffer, flags); |
343 jobject byte_buffer = 0; | 337 jobject byte_buffer = 0; |
344 if (result == MOJO_RESULT_OK) { | 338 if (result == MOJO_RESULT_OK) { |
345 byte_buffer = env->NewDirectByteBuffer(buffer, num_bytes); | 339 byte_buffer = env->NewDirectByteBuffer(buffer, num_bytes); |
346 } | 340 } |
347 return Java_CoreImpl_newNativeCodeAndBufferResult(env, result, byte_buffer) | 341 return Java_CoreImpl_newResultAndBuffer(env, result, byte_buffer).Release(); |
348 .Release(); | |
349 } | 342 } |
350 | 343 |
351 static int Unmap(JNIEnv* env, jobject jcaller, jobject buffer) { | 344 static int Unmap(JNIEnv* env, jobject jcaller, jobject buffer) { |
352 void* buffer_start = env->GetDirectBufferAddress(buffer); | 345 void* buffer_start = env->GetDirectBufferAddress(buffer); |
353 DCHECK(buffer_start); | 346 DCHECK(buffer_start); |
354 return MojoUnmapBuffer(buffer_start); | 347 return MojoUnmapBuffer(buffer_start); |
355 } | 348 } |
356 | 349 |
357 static jobject AsyncWait(JNIEnv* env, | 350 static jobject AsyncWait(JNIEnv* env, |
358 jobject jcaller, | 351 jobject jcaller, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr)); | 387 reinterpret_cast<AsyncWaitCallbackData*>(data_ptr)); |
395 Environment::GetDefaultAsyncWaiter()->CancelWait(id); | 388 Environment::GetDefaultAsyncWaiter()->CancelWait(id); |
396 } | 389 } |
397 | 390 |
398 bool RegisterCoreImpl(JNIEnv* env) { | 391 bool RegisterCoreImpl(JNIEnv* env) { |
399 return RegisterNativesImpl(env); | 392 return RegisterNativesImpl(env); |
400 } | 393 } |
401 | 394 |
402 } // namespace android | 395 } // namespace android |
403 } // namespace mojo | 396 } // namespace mojo |
OLD | NEW |