CCEnhanceAPI-android.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /****************************************************************************
  2. * Samsung API for cocos
  3. * Developed by Game Engine part
  4. *
  5. * Copyright 2015 by Mobile Solution Lab, MSG, SRC-NJ.
  6. * Wang Ying
  7. * All rights reserved.
  8. *
  9. * This software is the confidential and proprietary information of
  10. * Samsung Electronics, Inc. ("Confidential Information"). You
  11. * Shall not disclose such Confidential Information and shall use
  12. * it only in accordance with the terms of the license agreement
  13. * you entered into with Samsung
  14. ****************************************************************************/
  15. #include "platform/CCPlatformConfig.h"
  16. #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
  17. #include "platform/android/jni/JniHelper.h"
  18. #include "platform/android/CCEnhanceAPI-android.h"
  19. #include <android/log.h>
  20. #include <jni.h>
  21. #define LOG_TAG "CCEnhanceAPI_android Debug"
  22. #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
  23. #define CLASS_NAME "org/cocos2dx/lib/Cocos2dxHelper"
  24. // FIXME: using ndk-r10c will cause the next function could not be found. It may be a bug of ndk-r10c.
  25. // Here is the workaround method to fix the problem.
  26. // Fixed, at least, in NDK 12b
  27. //#ifdef __aarch64__
  28. //extern "C" size_t __ctype_get_mb_cur_max(void) {
  29. // return (size_t) sizeof(wchar_t);
  30. //}
  31. //#endif
  32. NS_CC_BEGIN
  33. EnhanceAPI::EnhanceAPI()
  34. {
  35. }
  36. EnhanceAPI::~EnhanceAPI()
  37. {
  38. }
  39. int EnhanceAPI::setResolutionPercent(int n)
  40. {
  41. JniMethodInfo t;
  42. int ret = -1;
  43. if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setResolutionPercent", "(I)I"))
  44. {
  45. ret = t.env->CallStaticIntMethod(t.classID, t.methodID, n);
  46. t.env->DeleteLocalRef(t.classID);
  47. }
  48. return ret;
  49. }
  50. int EnhanceAPI::setFPS(int fps)
  51. {
  52. JniMethodInfo t;
  53. int ret = -1;
  54. if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setFPS", "(I)I"))
  55. {
  56. ret = t.env->CallStaticIntMethod(t.classID, t.methodID, fps);
  57. t.env->DeleteLocalRef(t.classID);
  58. }
  59. return ret;
  60. }
  61. int EnhanceAPI::fastLoading(int sec)
  62. {
  63. JniMethodInfo t;
  64. int ret = -1;
  65. if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "fastLoading", "(I)I"))
  66. {
  67. ret = t.env->CallStaticIntMethod(t.classID, t.methodID, sec);
  68. t.env->DeleteLocalRef(t.classID);
  69. }
  70. return ret;
  71. }
  72. int EnhanceAPI::getTemperature()
  73. {
  74. JniMethodInfo t;
  75. int ret = -1;
  76. if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getTemperature", "()I"))
  77. {
  78. ret = t.env->CallStaticIntMethod(t.classID, t.methodID);
  79. t.env->DeleteLocalRef(t.classID);
  80. }
  81. return ret;
  82. }
  83. int EnhanceAPI::setLowPowerMode(bool enable)
  84. {
  85. JniMethodInfo t;
  86. int ret = -1;
  87. if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setLowPowerMode", "(Z)I"))
  88. {
  89. ret = t.env->CallStaticIntMethod(t.classID, t.methodID, enable);
  90. t.env->DeleteLocalRef(t.classID);
  91. }
  92. return ret;
  93. }
  94. NS_CC_END
  95. #endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID