#include "tcuAndroidUtil.hpp"
+#include <vector>
+
namespace tcu
{
namespace Android
{
using std::string;
+using std::vector;
+
+void checkJNIException (JNIEnv* env)
+{
+ if (env->ExceptionCheck())
+ {
+ env->ExceptionDescribe();
+ env->ExceptionClear();
+ throw std::runtime_error("Got JNI exception");
+ }
+}
+
+string getJNIStringValue (JNIEnv* env, jstring jniStr)
+{
+ const char* ptr = env->GetStringUTFChars(jniStr, DE_NULL);
+ const string str = string(ptr);
+
+ env->ReleaseStringUTFChars(jniStr, ptr);
+
+ return str;
+}
static string getIntentStringExtra (JNIEnv* env, jobject activity, const char* name)
{
env->DeleteLocalRef(extraName);
if (extraStr)
- {
- const char* ptr = env->GetStringUTFChars(extraStr, DE_NULL);
- string str = string(ptr);
- env->ReleaseStringUTFChars(extraStr, ptr);
- return str;
- }
+ return getJNIStringValue(env, extraStr);
else
return string();
}
}
}
+template<typename Type>
+const char* getJNITypeStr (void);
+
+template<>
+const char* getJNITypeStr<int> (void)
+{
+ return "I";
+}
+
+template<>
+const char* getJNITypeStr<string> (void)
+{
+ return "Ljava/lang/String;";
+}
+
+template<>
+const char* getJNITypeStr<vector<string> > (void)
+{
+ return "[Ljava/lang/String;";
+}
+
+template<typename FieldType>
+FieldType getStaticFieldValue (JNIEnv* env, jclass cls, jfieldID fieldId);
+
+template<>
+int getStaticFieldValue<int> (JNIEnv* env, jclass cls, jfieldID fieldId)
+{
+ DE_ASSERT(cls && fieldId);
+ return env->GetStaticIntField(cls, fieldId);
+}
+
+template<>
+string getStaticFieldValue<string> (JNIEnv* env, jclass cls, jfieldID fieldId)
+{
+ const jstring jniStr = (jstring)env->GetStaticObjectField(cls, fieldId);
+
+ if (jniStr)
+ return getJNIStringValue(env, jniStr);
+ else
+ return string();
+}
+
+template<>
+vector<string> getStaticFieldValue<vector<string> > (JNIEnv* env, jclass cls, jfieldID fieldId)
+{
+ const jobjectArray array = (jobjectArray)env->GetStaticObjectField(cls, fieldId);
+ vector<string> result;
+
+ checkJNIException(env);
+
+ if (array)
+ {
+ const int numElements = env->GetArrayLength(array);
+
+ for (int ndx = 0; ndx < numElements; ndx++)
+ {
+ const jstring jniStr = (jstring)env->GetObjectArrayElement(array, ndx);
+
+ checkJNIException(env);
+
+ if (jniStr)
+ result.push_back(getJNIStringValue(env, jniStr));
+ }
+ }
+
+ return result;
+}
+
+template<typename FieldType>
+FieldType getStaticField (JNIEnv* env, const char* className, const char* fieldName)
+{
+ const jclass cls = env->FindClass(className);
+ const jfieldID fieldId = cls ? env->GetStaticFieldID(cls, fieldName, getJNITypeStr<FieldType>()) : (jfieldID)0;
+
+ checkJNIException(env);
+
+ if (cls && fieldId)
+ return getStaticFieldValue<FieldType>(env, cls, fieldId);
+ else
+ return FieldType();
+}
+
+class ScopedJNIEnv
+{
+public:
+
+ ScopedJNIEnv (JavaVM* vm);
+ ~ScopedJNIEnv (void);
+
+ JavaVM* getVM (void) const { return m_vm; }
+ JNIEnv* getEnv (void) const { return m_env; }
+
+private:
+ JavaVM* const m_vm;
+ JNIEnv* m_env;
+ bool m_detach;
+};
+
+ScopedJNIEnv::ScopedJNIEnv (JavaVM* vm)
+ : m_vm (vm)
+ , m_env (DE_NULL)
+ , m_detach (false)
+{
+ const int getEnvRes = m_vm->GetEnv((void**)&m_env, JNI_VERSION_1_6);
+
+ if (getEnvRes == JNI_EDETACHED)
+ {
+ if (m_vm->AttachCurrentThread(&m_env, DE_NULL) != JNI_OK)
+ throw std::runtime_error("JNI AttachCurrentThread() failed");
+
+ m_detach = true;
+ }
+ else if (getEnvRes != JNI_OK)
+ throw std::runtime_error("JNI GetEnv() failed");
+
+ DE_ASSERT(m_env);
+}
+
+ScopedJNIEnv::~ScopedJNIEnv (void)
+{
+ if (m_detach)
+ m_vm->DetachCurrentThread();
+}
+
+void describePlatform (ANativeActivity* activity, std::ostream& dst)
+{
+ const ScopedJNIEnv env (activity->vm);
+ const char* const buildClass = "android/os/Build";
+ const char* const versionClass = "android/os/Build$VERSION";
+
+ static const struct
+ {
+ const char* classPath;
+ const char* className;
+ const char* fieldName;
+ } s_stringFields[] =
+ {
+ { buildClass, "Build", "BOARD" },
+ { buildClass, "Build", "BRAND" },
+ { buildClass, "Build", "DEVICE" },
+ { buildClass, "Build", "DISPLAY" },
+ { buildClass, "Build", "FINGERPRINT" },
+ { buildClass, "Build", "HARDWARE" },
+ { buildClass, "Build", "MANUFACTURER" },
+ { buildClass, "Build", "MODEL" },
+ { buildClass, "Build", "PRODUCT" },
+ { buildClass, "Build", "TAGS" },
+ { buildClass, "Build", "TYPE" },
+ { versionClass, "Build.VERSION", "RELEASE" },
+ };
+
+ for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_stringFields); ndx++)
+ dst << s_stringFields[ndx].className << "." << s_stringFields[ndx].fieldName
+ << ": " << getStaticField<string>(env.getEnv(), s_stringFields[ndx].classPath, s_stringFields[ndx].fieldName)
+ << "\n";
+
+ dst << "Build.VERSION.SDK_INT: " << getStaticField<int>(env.getEnv(), versionClass, "SDK_INT") << "\n";
+
+ {
+ const vector<string> supportedAbis = getStaticField<vector<string> >(env.getEnv(), buildClass, "SUPPORTED_ABIS");
+
+ dst << "Build.SUPPORTED_ABIS: ";
+
+ for (size_t ndx = 0; ndx < supportedAbis.size(); ndx++)
+ dst << (ndx != 0 ? ", " : "") << supportedAbis[ndx];
+
+ dst << "\n";
+ }
+}
+
} // Android
} // tcu
* \brief Win32 platform port.
*//*--------------------------------------------------------------------*/
+// \todo [2016-01-22 pyry] GetVersionEx() used by getOSInfo() is deprecated.
+// Find a way to get version info without using deprecated APIs.
+#pragma warning(disable : 4996)
+
#include "tcuWin32Platform.hpp"
#include "tcuWGLContextFactory.hpp"
#include "tcuFunctionLibrary.hpp"
+#include "tcuFormatUtil.hpp"
+
+#include "deMemory.h"
#if defined(DEQP_SUPPORT_EGL)
# include "tcuWin32EGLNativeDisplayFactory.hpp"
{
public:
VulkanLibrary (void)
- : m_library ("vulkan-1.dll")
+ : m_library ("nv-vk64.dll")
, m_driver (m_library)
{
}
return new VulkanLibrary();
}
+const char* getProductTypeName (WORD productType)
+{
+ switch (productType)
+ {
+ case VER_NT_DOMAIN_CONTROLLER: return "Windows Server (domain controller)";
+ case VER_NT_SERVER: return "Windows Server";
+ case VER_NT_WORKSTATION: return "Windows NT";
+ default: return DE_NULL;
+ }
+}
+
+static void getOSInfo (std::ostream& dst)
+{
+ OSVERSIONINFOEX osInfo;
+
+ deMemset(&osInfo, 0, sizeof(osInfo));
+ osInfo.dwOSVersionInfoSize = (DWORD)sizeof(osInfo);
+
+ GetVersionEx((OSVERSIONINFO*)&osInfo);
+
+ {
+ const char* const productName = getProductTypeName(osInfo.wProductType);
+
+ if (productName)
+ dst << productName;
+ else
+ dst << "unknown product " << tcu::toHex(osInfo.wProductType);
+ }
+
+ dst << " " << osInfo.dwMajorVersion << "." << osInfo.dwMinorVersion
+ << ", service pack " << osInfo.wServicePackMajor << "." << osInfo.wServicePackMinor
+ << ", build " << osInfo.dwBuildNumber;
+}
+
+const char* getProcessorArchitectureName (WORD arch)
+{
+ switch (arch)
+ {
+ case PROCESSOR_ARCHITECTURE_AMD64: return "AMD64";
+ case PROCESSOR_ARCHITECTURE_ARM: return "ARM";
+ case PROCESSOR_ARCHITECTURE_IA64: return "IA64";
+ case PROCESSOR_ARCHITECTURE_INTEL: return "INTEL";
+ case PROCESSOR_ARCHITECTURE_UNKNOWN: return "UNKNOWN";
+ default: return DE_NULL;
+ }
+}
+
+static void getProcessorInfo (std::ostream& dst)
+{
+ SYSTEM_INFO sysInfo;
+
+ deMemset(&sysInfo, 0, sizeof(sysInfo));
+ GetSystemInfo(&sysInfo);
+
+ dst << "arch ";
+ {
+ const char* const archName = getProcessorArchitectureName(sysInfo.wProcessorArchitecture);
+
+ if (archName)
+ dst << archName;
+ else
+ dst << tcu::toHex(sysInfo.wProcessorArchitecture);
+ }
+
+ dst << ", level " << tcu::toHex(sysInfo.wProcessorLevel) << ", revision " << tcu::toHex(sysInfo.wProcessorRevision);
+}
+
+void Win32Platform::describePlatform (std::ostream& dst) const
+{
+ dst << "OS: ";
+ getOSInfo(dst);
+ dst << "\n";
+
+ dst << "CPU: ";
+ getProcessorInfo(dst);
+ dst << "\n";
+}
+
} // tcu
// Create platform