display_synchronizer_jni.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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
  3. // found in the LICENSE file.
  4. // This file is of the same format as file that generated by
  5. // base/android/jni_generator/jni_generator.py
  6. // For
  7. // com/google/vr/cardboard/DisplaySynchronizer
  8. // Local modification includes:
  9. // 1. Remove all implementaiton, only keep definition.
  10. // 2. Use absolute path instead of relative path.
  11. // 3. Removed all helper functions such as: Create.
  12. // 4. Added function RegisterDisplaySynchronizerNatives at the end of this file.
  13. #ifndef com_google_vr_cardboard_DisplaySynchronizer_JNI
  14. #define com_google_vr_cardboard_DisplaySynchronizer_JNI
  15. #include "base/android/jni_android.h"
  16. // ----------------------------------------------------------------------------
  17. // Native JNI methods
  18. // ----------------------------------------------------------------------------
  19. #include <jni.h>
  20. #include <atomic>
  21. #include <type_traits>
  22. #include "base/android/jni_generator/jni_generator_helper.h"
  23. #include "base/android/jni_int_wrapper.h"
  24. // Step 1: forward declarations.
  25. namespace {
  26. const char kDisplaySynchronizerClassPath[] =
  27. "com/google/vr/cardboard/DisplaySynchronizer";
  28. // Leaking this jclass as we cannot use LazyInstance from some threads.
  29. std::atomic<jclass> g_DisplaySynchronizer_clazz __attribute__((unused))
  30. (nullptr);
  31. #define DisplaySynchronizer_clazz(env) \
  32. base::android::LazyGetClass(env, kDisplaySynchronizerClassPath, \
  33. &g_DisplaySynchronizer_clazz)
  34. } // namespace
  35. namespace DisplaySynchronizer {
  36. extern "C" __attribute__((visibility("default"))) jlong
  37. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeCreate(
  38. JNIEnv* env,
  39. jobject jcaller,
  40. jclass classLoader,
  41. jobject appContext);
  42. // Step 2: method stubs.
  43. extern "C" __attribute__((visibility("default"))) void
  44. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeDestroy(
  45. JNIEnv* env,
  46. jobject jcaller,
  47. jlong nativeDisplaySynchronizer);
  48. extern "C" __attribute__((visibility("default"))) void
  49. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeReset(
  50. JNIEnv* env,
  51. jobject jcaller,
  52. jlong nativeDisplaySynchronizer,
  53. jlong expectedInterval,
  54. jlong vsyncOffset);
  55. extern "C" __attribute__((visibility("default"))) void
  56. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeUpdate(
  57. JNIEnv* env,
  58. jobject jcaller,
  59. jlong nativeDisplaySynchronizer,
  60. jlong syncTime,
  61. jint currentRotation);
  62. extern "C" __attribute__((visibility("default"))) void
  63. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeOnMetricsChanged(
  64. JNIEnv* env,
  65. jobject obj,
  66. jlong native_object);
  67. // Step 3: RegisterNatives.
  68. static const JNINativeMethod kMethodsDisplaySynchronizer[] = {
  69. {"nativeCreate",
  70. "("
  71. "Ljava/lang/ClassLoader;"
  72. "Landroid/content/Context;"
  73. ")"
  74. "J",
  75. reinterpret_cast<void*>(
  76. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeCreate)},
  77. {"nativeDestroy",
  78. "("
  79. "J"
  80. ")"
  81. "V",
  82. reinterpret_cast<void*>(
  83. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeDestroy)},
  84. {"nativeReset",
  85. "("
  86. "J"
  87. "J"
  88. "J"
  89. ")"
  90. "V",
  91. reinterpret_cast<void*>(
  92. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeReset)},
  93. {"nativeUpdate",
  94. "("
  95. "J"
  96. "J"
  97. "I"
  98. ")"
  99. "V",
  100. reinterpret_cast<void*>(
  101. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeUpdate)},
  102. {"nativeOnMetricsChanged",
  103. "("
  104. "J"
  105. ")"
  106. "V",
  107. reinterpret_cast<void*>(
  108. Java_com_google_vr_cardboard_DisplaySynchronizer_nativeOnMetricsChanged)},
  109. };
  110. static bool RegisterNativesImpl(JNIEnv* env) {
  111. if (base::android::IsSelectiveJniRegistrationEnabled(env))
  112. return true;
  113. const int kMethodsDisplaySynchronizerSize =
  114. std::extent<decltype(kMethodsDisplaySynchronizer)>();
  115. if (env->RegisterNatives(DisplaySynchronizer_clazz(env),
  116. kMethodsDisplaySynchronizer,
  117. kMethodsDisplaySynchronizerSize) < 0) {
  118. jni_generator::HandleRegistrationError(env, DisplaySynchronizer_clazz(env),
  119. __FILE__);
  120. return false;
  121. }
  122. return true;
  123. }
  124. static bool RegisterDisplaySynchronizerNatives(JNIEnv* env) {
  125. return RegisterNativesImpl(env);
  126. }
  127. } // namespace DisplaySynchronizer
  128. #endif // com_google_vr_cardboard_DisplaySynchronizer_JNI