Skip to content

Commit

Permalink
Updating samples to use clang.
Browse files Browse the repository at this point in the history
Change-Id: Ibe581bd29eca6f4e25b90da143781c290fa92129
  • Loading branch information
claywilkinson committed Jan 11, 2018
1 parent 1e1f1e7 commit 7b648f2
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 53 deletions.
9 changes: 5 additions & 4 deletions samples-android/ButtonClicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ android {

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
arguments "-DANDROID_STL=c++_static",
"-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}",
cppFlags "-std=c++11 -frtti -Wall -Werror"
arguments "-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}",
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}",
"-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer"
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer",
"-DANDROID_STL=c++_static",
"-DANDROID_TOOLCHAIN=clang"
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions samples-android/CollectAllTheStarsNative/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ android {

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
cppFlags "-std=c++11 -frtti -Wall -Werror"
arguments "-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}" ,
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}" ,
"-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
"-DJSON_PATH=${project(':Common:gpg-sdk').projectDir}/../external/jsoncpp/",
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer" ,
"-DANDROID_STL=c++_static"
"-DANDROID_STL=c++_static",
"-DANDROID_TOOLCHAIN=clang"
}

}
Expand Down
7 changes: 4 additions & 3 deletions samples-android/Common/JuiHelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ android {

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
cppFlags "-std=c++11 -frtti -Wall -Werror"
targets "juihelper"
arguments "-DANDROID_STL=c++_static",
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}"
arguments "-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}",
"-DANDROID_STL=c++_static",
"-DANDROID_TOOLCHAIN=clang"
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions samples-android/Common/NDKHelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ android {

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
cppFlags "-std=c++11 -frtti -Wall -Werror"
targets "ndkhelper"
arguments "-DANDROID_STL=c++_static",
"-DNDK_HELPER_PATH=${project(':Common:JuiHelper').projectDir}"
arguments "-DNDK_HELPER_PATH=${project(':Common:JuiHelper').projectDir}",
"-DANDROID_STL=c++_static",
"-DANDROID_TOOLCHAIN=clang"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions samples-android/Common/NDKHelper/src/main/cpp/GLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void GLContext::InitGLES() {
//
//Initialize OpenGL ES 3 if available
//
const char *versionStr = (const char *)glGetString(GL_VERSION);
const char *versionStr = reinterpret_cast<const char*>(glGetString(GL_VERSION));
if (strstr(versionStr, "OpenGL ES 3.") && gl3stubInit()) {
es3_supported_ = true;
gl_version_ = 3.0f;
Expand Down Expand Up @@ -92,7 +92,7 @@ bool GLContext::InitEGLSurface() {
* Below, we select an EGLConfig with at least 8 bits per color
* component compatible with on-screen windows
*/
const EGLint attribs[] = { EGL_RENDERABLE_TYPE,
const EGLint attribs0[] = { EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT, //Request opengl ES2.0
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_DEPTH_SIZE,
Expand All @@ -101,7 +101,7 @@ bool GLContext::InitEGLSurface() {
depth_size_ = 24;

EGLint num_configs;
eglChooseConfig(display_, attribs, &config_, 1, &num_configs);
eglChooseConfig(display_, attribs0, &config_, 1, &num_configs);

if (msaa_size_ > 1 && !num_configs) {
LOGW("No EGL config with MSAA");
Expand Down
46 changes: 24 additions & 22 deletions samples-android/Common/NDKHelper/src/main/cpp/JNIHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace ndk_helper {
* Singleton
*/
JNIHelper *JNIHelper::GetInstance() {
static JNIHelper helper;
return &helper;
static JNIHelper* pHelper = new JNIHelper();
return pHelper;
}

/*
Expand Down Expand Up @@ -73,14 +73,14 @@ void JNIHelper::Init(ANativeActivity *activity, const char *helper_class_name) {
jmethodID midGetPackageName = env->GetMethodID(
android_content_Context, "getPackageName", "()Ljava/lang/String;");

jstring packageName = (jstring)
env->CallObjectMethod(helper.activity_->clazz, midGetPackageName);
jstring packageName = static_cast<jstring>(
env->CallObjectMethod(helper.activity_->clazz, midGetPackageName));
const char *appname = env->GetStringUTFChars(packageName, NULL);
helper.app_bunlde_name_ = std::string(appname);

//Instantiate JNIHelper class
jclass cls = helper.RetrieveClass(env, helper_class_name);
helper.jni_helper_java_class_ = (jclass) env->NewGlobalRef(cls);
helper.jni_helper_java_class_ = static_cast<jclass>(env->NewGlobalRef(cls));

jmethodID constructor =
env->GetMethodID(helper.jni_helper_java_class_, "<init>",
Expand All @@ -91,8 +91,8 @@ void JNIHelper::Init(ANativeActivity *activity, const char *helper_class_name) {
helper.jni_helper_java_ref_ = env->NewGlobalRef(helper.jni_helper_java_ref_);

//Get app label
jstring labelName = (jstring)
helper.CallObjectMethod("getApplicationName", "()Ljava/lang/String;");
jstring labelName = static_cast<jstring>(
helper.CallObjectMethod("getApplicationName", "()Ljava/lang/String;"));
const char *label = env->GetStringUTFChars(labelName, NULL);
helper.app_label_ = std::string(label);

Expand Down Expand Up @@ -158,9 +158,9 @@ bool JNIHelper::ReadFile(const char *fileName,
if (f) {
LOGI("reading:%s", s.c_str());
f.seekg(0, std::ifstream::end);
int32_t fileSize = f.tellg();
long long int fileSize = f.tellg();
f.seekg(0, std::ifstream::beg);
buffer_ref->reserve(fileSize);
buffer_ref->reserve(static_cast<unsigned long>(fileSize));
buffer_ref->assign(std::istreambuf_iterator<char>(f),
std::istreambuf_iterator<char>());
f.close();
Expand All @@ -173,8 +173,8 @@ bool JNIHelper::ReadFile(const char *fileName,
if (!assetFile) {
return false;
}
uint8_t *data = (uint8_t *)AAsset_getBuffer(assetFile);
int32_t size = AAsset_getLength(assetFile);
const uint8_t *data = static_cast<const uint8_t*>(AAsset_getBuffer(assetFile));
size_t size = static_cast<size_t>(AAsset_getLength(assetFile));
if (data == NULL) {
AAsset_close(assetFile);

Expand Down Expand Up @@ -250,11 +250,11 @@ uint32_t JNIHelper::LoadTexture(const char *file_name, int32_t *outWidth,
int32_t height = env->GetIntField(out, fidHeight);
if (!ret) {
glDeleteTextures(1, &tex);
tex = -1;
tex = 0xffff;
LOGI("Texture load failed %s", file_name);
}
LOGI("Loaded texture original size:%dx%d alpha:%d", width, height,
(int32_t) alpha);
static_cast<int32_t>(alpha));
if (outWidth != NULL) {
*outWidth = width;
}
Expand Down Expand Up @@ -287,16 +287,16 @@ std::string JNIHelper::ConvertString(const char *str, const char *encode) {
JNIEnv *env = AttachCurrentThread();
env->PushLocalFrame(16);

int32_t iLength = strlen((const char *)str);
jsize iLength = static_cast<jsize>(strlen(str));

jbyteArray array = env->NewByteArray(iLength);
env->SetByteArrayRegion(array, 0, iLength, (const signed char *)str);
env->SetByteArrayRegion(array, 0, iLength, reinterpret_cast<const jbyte*>(str));

jstring strEncode = env->NewStringUTF(encode);

jclass cls = env->FindClass("java/lang/String");
jmethodID ctor = env->GetMethodID(cls, "<init>", "([BLjava/lang/String;)V");
jstring object = (jstring) env->NewObject(cls, ctor, array, strEncode);
jstring object = static_cast<jstring>(env->NewObject(cls, ctor, array, strEncode));

const char *cparam = env->GetStringUTFChars(object, NULL);

Expand Down Expand Up @@ -332,8 +332,8 @@ std::string JNIHelper::GetStringResource(const std::string& resourceName)
JNIEnv *env = AttachCurrentThread();
jstring name = env->NewStringUTF(resourceName.c_str());

jstring ret = (jstring)
CallObjectMethod("getStringResource", "(Ljava/lang/String;)Ljava/lang/String;", name);
jstring ret = static_cast<jstring>(
CallObjectMethod("getStringResource", "(Ljava/lang/String;)Ljava/lang/String;", name));

const char *resource = env->GetStringUTFChars(ret, NULL);
std::string s = std::string(resource);
Expand Down Expand Up @@ -389,7 +389,7 @@ jclass JNIHelper::RetrieveClass(JNIEnv *jni, const char *class_name) {

jstring str_class_name = jni->NewStringUTF(class_name);
jclass class_retrieved =
(jclass) jni->CallObjectMethod(cls, find_class, str_class_name);
static_cast<jclass>(jni->CallObjectMethod(cls, find_class, str_class_name));
jni->DeleteLocalRef(str_class_name);
jni->DeleteLocalRef(activity_class);
jni->DeleteLocalRef(class_loader);
Expand All @@ -411,7 +411,7 @@ jstring JNIHelper::GetExternalFilesDirJString(JNIEnv *env) {
jclass cls_File = env->FindClass("java/io/File");
jmethodID mid_getPath =
env->GetMethodID(cls_File, "getPath", "()Ljava/lang/String;");
jstring obj_Path = (jstring) env->CallObjectMethod(obj_File, mid_getPath);
jstring obj_Path = static_cast<jstring>(env->CallObjectMethod(obj_File, mid_getPath));

return obj_Path;
}
Expand Down Expand Up @@ -622,15 +622,17 @@ void JNIHelper::RunOnUiThread(std::function<void()> callback) {

// Allocate temporary function object to be passed around
std::function<void()> *pCallback = new std::function<void()>(callback);
env->CallVoidMethod(jni_helper_java_ref_, mid, (int64_t) pCallback);
env->CallVoidMethod(jni_helper_java_ref_, mid, reinterpret_cast<int64_t>(pCallback));
}

// This JNI function is invoked from UIThread asynchronously
extern "C" {
JNIEXPORT void
Java_com_sample_helper_NDKHelper_RunOnUiThreadHandler(JNIEnv *env, jobject thiz,
int64_t pointer) {
std::function<void()> *pCallback = (std::function<void()> *)pointer;
#pragma unused (env)
#pragma unused (thiz)
std::function<void()> *pCallback = reinterpret_cast< std::function<void()> *>(pointer);
(*pCallback)();

// Deleting temporary object
Expand Down
7 changes: 4 additions & 3 deletions samples-android/Common/NDKHelper/src/main/cpp/JNIHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,11 @@ class JNIHelper {
*/
JNIEnv *AttachCurrentThread() {
JNIEnv *env;
if (activity_->vm->GetEnv((void **)&env, JNI_VERSION_1_4) == JNI_OK)
if (activity_->vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_4) == JNI_OK)
return env;
activity_->vm->AttachCurrentThread(&env, NULL);
pthread_key_create((int32_t *)activity_, DetachCurrentThreadDtor);
pthread_key_create(
reinterpret_cast<pthread_key_t *>(activity_), DetachCurrentThreadDtor);
return env;
}

Expand Down Expand Up @@ -285,7 +286,7 @@ class JNIHelper {
*/
static void DetachCurrentThreadDtor(void *p) {
LOGI("detached current thread");
ANativeActivity *activity = (ANativeActivity *)p;
ANativeActivity *activity = reinterpret_cast<ANativeActivity *>(p);
activity->vm->DetachCurrentThread();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace ndk_helper {

PerfMonitor::PerfMonitor()
: current_FPS_(0), tv_last_sec_(0), last_tick_(0.f), tickindex_(0),
: current_FPS_(0), tv_last_sec_(0), last_tick_(0), tickindex_(0),
ticksum_(0) {
for (int32_t i = 0; i < NUM_SAMPLES; ++i)
ticklist_[i] = 0;
Expand Down
31 changes: 26 additions & 5 deletions samples-android/Common/gpg-sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/* Copyright (C) 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
sub module to download the Google Play games
*/
project.ext {
if (!project.hasProperty('gpg_sdk_link')) {
gpg_sdk_link = 'https://developers.google.com/games/services/downloads/gpg-cpp-sdk.v3.0.zip'
gpg_sdk_link = System.getenv("GPG_SDK_LINK")
if (gpg_sdk_link == null || gpg_sdk_link.isEmpty()) {
gpg_sdk_link = 'https://developers.google.com/games/services/downloads/gpg-cpp-sdk.v3.0.zip'
}
}
}
task download_and_stage_gpg_sdk(dependsOn:'unzip_gpg_sdk') {
Expand All @@ -24,19 +41,23 @@ task fetch_gpg_cpp_sdk () {
fetch_gpg_cpp_sdk.description = "Download the gpg sdk from the specified location"

task unzip_gpg_sdk() {
def dest = file( "${project.projectDir}/gpg-cpp-sdk")
doFirst {
if (!file('gpg-cpp-sdk').exists()) {
if (!dest.exists()) {
copy {
from(zipTree('gpg_cpp_sdk.zip')) {
exclude 'gpg-cpp-sdk/ios/**/*'
include 'gpg-cpp-sdk/android/**/*'
}

into { project.projectDir }
}
} else {
println "Skipping sdk unzipping, ${dest.absolutePath} exists"
}
}
outputs.dir('gpg-cpp-sdk/android')
outputs.upToDateWhen {file('gpg-cpp-sdk/android').exists()}
outputs.upToDateWhen {file("${dest.absolutePath}/android").exists() &&
file('gpg-cpp-sdk/android/lib/c++/arm64-v8a/libgpg.a').exists()}
description = "Unzips the GPG SDK into the correct dir for NDK"
dependsOn fetch_gpg_cpp_sdk
}
Expand All @@ -51,4 +72,4 @@ task clean() {
}
}

defaultTasks = ['download_and_stage_gpg_sdk']
defaultTasks = ['unzip_gpg_sdk']
5 changes: 3 additions & 2 deletions samples-android/Minimalist/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ android {

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
cppFlags "-std=c++11 -frtti -Wall -Werror"
arguments "-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
"-DANDROID_STL=c++_static"
"-DANDROID_STL=c++_static",
"-DANDROID_TOOLCHAIN=clang"
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions samples-android/TbmpSkeletonNative/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ android {

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
cppFlags "-std=c++11 -frtti -Wall -Werror"
arguments "-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}" ,
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}" ,
"-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
"-DJSON_PATH=${project(':Common:gpg-sdk').projectDir}/../external/jsoncpp/",
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer" ,
"-DANDROID_STL=c++_static"
"-DANDROID_STL=c++_static",
"-DANDROID_TOOLCHAIN=clang"
}

}
Expand Down
5 changes: 3 additions & 2 deletions samples-android/Teapot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ apply plugin: 'com.android.application'

externalNativeBuild {
cmake {
cppFlags "-std=c++11 -Wall -frtti"
cppFlags "-std=c++11 -frtti -Wall -Werror"
arguments "-DJUI_HELPER_PATH=${project(':Common:JuiHelper').projectDir}" ,
"-DNDK_HELPER_PATH=${project(':Common:NDKHelper').projectDir}" ,
"-DGPG_SDK_PATH=${project(':Common:gpg-sdk').projectDir}/gpg-cpp-sdk/android",
"-DTEAPOT_RENDERER_PATH=${project(':Common').projectDir}/TeapotRenderer" ,
"-DANDROID_STL=c++_static"
"-DANDROID_STL=c++_static",
"-DANDROID_TOOLCHAIN=clang"
}

}
Expand Down
2 changes: 1 addition & 1 deletion samples-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ allprojects {
// As the plugin has created the build tasks, add the gpg-sdk task to
// the task dependencies so it gets done before compiling
tasks.whenTaskAdded {
task->project(':Common:gpg-sdk').defaultTasks.each {
task-> if (!task.name.endsWith("clean")) project(':Common:gpg-sdk').defaultTasks.each {
t->task.dependsOn project(':Common:gpg-sdk').tasks[t]
}
}
Expand Down

0 comments on commit 7b648f2

Please sign in to comment.