Skip to content
This repository has been archived by the owner on Mar 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #62 from googlesamples/release-electra
Browse files Browse the repository at this point in the history
release electra.
  • Loading branch information
jguomoto committed Jan 12, 2016
2 parents bf26788 + 4b436eb commit 809c572
Show file tree
Hide file tree
Showing 60 changed files with 490 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ protected void onResume() {
protected void onPause() {
super.onPause();
mGLView.onPause();
if (mIsSurfaceCreated) {
TangoJNINative.freeContent();
mIsSurfaceCreated = false;
}
TangoJNINative.deleteResources();

// Disconnect from Tango Service, release all the resources that the app is
// holding from Tango Service.
Expand All @@ -173,6 +170,12 @@ protected void onPause() {
// Stop the debug text UI update loop.
mHandler.removeCallbacksAndMessages(null);
}

@Override
protected void onDestroy() {
super.onDestroy();
TangoJNINative.destroyActivity();
}

@Override
public void onClick(View v) {
Expand Down Expand Up @@ -349,6 +352,9 @@ private void setupUIComponents() {

// OpenGL view where all of the graphics are drawn.
mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view);

// Configure OpenGL renderer
mGLView.setEGLContextClientVersion(2);

// Configure OpenGL renderer
mRenderer = new Renderer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class TangoJNINative {
*/
public static native int initialize(AreaDescriptionActivity activity);

/**
* Signal that the activity has been destroyed and remove any references.
*/
public static native void destroyActivity();

/**
* Setup the configuration file of the Tango Service. We are also setting up
* the auto-recovery option from here.
Expand All @@ -59,9 +64,9 @@ public static native int setupConfig(boolean isAreaLearningEnabled,
public static native void disconnect();

/**
* Release/reset all resources that are allocated from the native code.
* Reset Pose Data and release non-GL resources that are allocated from the native code.
*/
public static native void freeContent();
public static native void deleteResources();

/**
* Allocate OpenGL resources for rendering.
Expand Down
30 changes: 21 additions & 9 deletions area-description-jni-example/app/src/main/jni/area_learning_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ void AreaLearningApp::onTangoEventAvailable(const TangoEvent* event) {
}
}

AreaLearningApp::AreaLearningApp() {
tango_core_version_string_ = "N/A";
loaded_adf_string_ = "Loaded ADF: N/A";
}
AreaLearningApp::AreaLearningApp()
: tango_core_version_string_("N/A"),
loaded_adf_string_("Loaded ADF: N/A"),
calling_activity_obj_(nullptr),
on_saving_adf_progress_updated_(nullptr) {}

AreaLearningApp::~AreaLearningApp() {
TangoConfig_free(tango_config_);
JNIEnv* env;
java_vm_->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
env->DeleteGlobalRef(calling_activity_obj_);
}

int AreaLearningApp::TangoInitialize(JNIEnv* env, jobject caller_activity) {
Expand All @@ -91,6 +89,14 @@ int AreaLearningApp::TangoInitialize(JNIEnv* env, jobject caller_activity) {
return ret;
}

void AreaLearningApp::ActivityDestroyed() {
JNIEnv* env;
java_vm_->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
env->DeleteGlobalRef(calling_activity_obj_);
calling_activity_obj_ = nullptr;
on_saving_adf_progress_updated_ = nullptr;
}

int AreaLearningApp::TangoSetupConfig(bool is_area_learning_enabled,
bool is_loading_adf) {
// Here, we'll configure the service to run in the way we'd want. For this
Expand Down Expand Up @@ -291,9 +297,9 @@ void AreaLearningApp::Render() {
main_scene_.Render(cur_pose, pose_data_.IsRelocalized());
}

void AreaLearningApp::FreeContent() {
void AreaLearningApp::DeleteResources() {
main_scene_.DeleteResources();
pose_data_.ResetPoseData();
main_scene_.FreeGLContent();
}

bool AreaLearningApp::IsRelocalized() {
Expand Down Expand Up @@ -376,6 +382,12 @@ std::string AreaLearningApp::GetTangoServiceVersion() {
void AreaLearningApp::OnAdfSavingProgressChanged(int progress) {
// Here, we notify the Java activity that we'd like it to update the saving
// Adf progress.
if (calling_activity_obj_ == nullptr ||
on_saving_adf_progress_updated_ == nullptr) {
LOGE("AreaLearningApp: Cannot reference activity on ADF saving progress changed.");
return;
}

JNIEnv* env;
java_vm_->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
env->CallVoidMethod(calling_activity_obj_, on_saving_adf_progress_updated_,
Expand Down
10 changes: 8 additions & 2 deletions area-description-jni-example/app/src/main/jni/jni_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Java_com_projecttango_experiments_nativearealearning_TangoJNINative_initialize(
return app.TangoInitialize(env, activity);
}

JNIEXPORT void JNICALL
Java_com_projecttango_experiments_nativearealearning_TangoJNINative_destroyActivity(
JNIEnv*, jobject) {
app.ActivityDestroyed();
}

JNIEXPORT jint JNICALL
Java_com_projecttango_experiments_nativearealearning_TangoJNINative_setupConfig(
JNIEnv*, jobject, bool is_area_learningEnabled, bool is_loading_adf) {
Expand Down Expand Up @@ -88,9 +94,9 @@ Java_com_projecttango_experiments_nativearealearning_TangoJNINative_render(
}

JNIEXPORT void JNICALL
Java_com_projecttango_experiments_nativearealearning_TangoJNINative_freeContent(
Java_com_projecttango_experiments_nativearealearning_TangoJNINative_deleteResources(
JNIEnv*, jobject) {
app.FreeContent();
app.DeleteResources();
}

JNIEXPORT jboolean JNICALL
Expand Down
2 changes: 1 addition & 1 deletion area-description-jni-example/app/src/main/jni/scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void Scene::InitGLContent() {
tango_gl::GestureCamera::CameraType::kThirdPerson);
}

void Scene::FreeGLContent() {
void Scene::DeleteResources() {
delete gesture_camera_;
delete axis_;
delete frustum_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class AreaLearningApp {
// The activity object is used for checking if the API version is outdated.
int TangoInitialize(JNIEnv* env, jobject caller_activity);

// When the Android activity is destroyed, signal the JNI layer to remove
// references to the activity. This should be called from the onDestroy()
// callback of the parent activity lifecycle.
void ActivityDestroyed();

// Setup the configuration file for the Tango Service. We'll also se whether
// we'd like auto-recover enabled.
//
Expand Down Expand Up @@ -119,8 +124,8 @@ class AreaLearningApp {
// Main render loop.
void Render();

// Release/reset all resources that allocate from the program.
void FreeContent();
// Reset pose data and release resources that allocate from the program.
void DeleteResources();

// Return true if Tango has relocalized to the current ADF at least once.
bool IsRelocalized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class Scene {
// Allocate OpenGL resources for rendering.
void InitGLContent();

// Release OpenGL resources allocated.
void FreeGLContent();
// Release non-GL resources.
void DeleteResources();

// Setup GL view port.
void SetupViewPort(int w, int h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ protected void onCreate(Bundle savedInstanceState) {

// OpenGL view where all of the graphics are drawn
mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view);

// Configure OpenGL renderer
mGLView.setEGLContextClientVersion(2);

// Set up button click listeners
mMotionReset.setOnClickListener(this);
Expand Down Expand Up @@ -165,7 +168,7 @@ protected void onCreate(Bundle savedInstanceState) {
protected void onResume() {
super.onResume();
mGLView.onResume();

// Setup the configuration for the TangoService.
TangoJNINative.setupConfig();

Expand All @@ -191,7 +194,7 @@ protected void onResume() {
protected void onPause() {
super.onPause();
mGLView.onPause();
TangoJNINative.freeGLContent();
TangoJNINative.deleteResources();

// Disconnect from Tango Service, release all the resources that the app is
// holding from Tango Service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class TangoJNINative {
// holding from the Tango Service.
public static native void disconnect();

// Release all OpenGL resources that are allocated from the program.
public static native void freeGLContent();
// Delete non-GL data structures that are allocated from the program.
public static native void deleteResources();

// Allocate OpenGL resources for rendering.
public static native void initGlContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,14 @@ void AugmentedRealityApp::Render() {
pose_data_.GetExtrinsicsAppliedOpenGLWorldFrame(color_camera_pose);
if (status != TANGO_SUCCESS) {
LOGE(
"AugmentedRealityApp: Failed to update video overlay texture with"
"AugmentedRealityApp: Failed to update video overlay texture with "
"error code: %d",
status);
}
main_scene_.Render(color_camera_pose);
}

void AugmentedRealityApp::FreeGLContent() { main_scene_.FreeGLContent(); }
void AugmentedRealityApp::DeleteResources() { main_scene_.DeleteResources(); }

std::string AugmentedRealityApp::GetPoseString() {
std::lock_guard<std::mutex> lock(pose_mutex_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ Java_com_projecttango_experiments_nativeaugmentedreality_TangoJNINative_render(
}

JNIEXPORT void JNICALL
Java_com_projecttango_experiments_nativeaugmentedreality_TangoJNINative_freeGLContent(
Java_com_projecttango_experiments_nativeaugmentedreality_TangoJNINative_deleteResources(
JNIEnv*, jobject) {
app.FreeGLContent();
app.DeleteResources();
}

JNIEXPORT jstring JNICALL
Expand Down
4 changes: 2 additions & 2 deletions augmented-reality-jni-example/app/src/main/jni/scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ void Scene::InitGLContent() {
tango_gl::GestureCamera::CameraType::kThirdPerson);
}

void Scene::FreeGLContent() {
delete video_overlay_;
void Scene::DeleteResources() {
delete gesture_camera_;
delete video_overlay_;
delete axis_;
delete frustum_;
delete trace_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class AugmentedRealityApp {
// Main render loop.
void Render();

// Release all OpenGL resources that allocate from the program.
void FreeGLContent();
// Release all non-OpenGL resources that allocate from the program.
void DeleteResources();

// Retrun pose debug string.
std::string GetPoseString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class Scene {
// Allocate OpenGL resources for rendering.
void InitGLContent();

// Release OpenGL resources allocated.
void FreeGLContent();
// Release non-OpenGL resources.
void DeleteResources();

// Setup GL view port.
// @param: x, left of the screen.
Expand Down
1 change: 1 addition & 0 deletions hello-tango-jni-example/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<application
android:allowBackup="true"
Expand Down
2 changes: 2 additions & 0 deletions motion-tracking-jni-example/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />

<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ protected void onCreate(Bundle savedInstanceState) {

// OpenGL view where all of the graphics are drawn
mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view);

// Configure OpenGL renderer
mGLView.setEGLContextClientVersion(2);

// Set up button click listeners
mMotionReset.setOnClickListener(this);
Expand Down Expand Up @@ -191,7 +194,7 @@ protected void onResume() {
protected void onPause() {
super.onPause();
mGLView.onPause();
TangoJNINative.freeGLContent();
TangoJNINative.deleteResources();

// Disconnect from Tango Service, release all the resources that the app is
// holding from Tango Service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class TangoJNINative {
// holding from the Tango Service.
public static native void disconnect();

// Release all OpenGL resources that are allocated from the program.
public static native void freeGLContent();
// Release all resources that are allocated from the program.
public static native void deleteResources();

// Allocate OpenGL resources for rendering.
public static native void initGlContent();
Expand Down
4 changes: 2 additions & 2 deletions motion-tracking-jni-example/app/src/main/jni/jni_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ Java_com_projecttango_experiments_nativemotiontracking_TangoJNINative_render(
}

JNIEXPORT void JNICALL
Java_com_projecttango_experiments_nativemotiontracking_TangoJNINative_freeGLContent(
Java_com_projecttango_experiments_nativemotiontracking_TangoJNINative_deleteResources(
JNIEnv*, jobject) {
app.FreeGLContent();
app.DeleteResources();
}

JNIEXPORT jstring JNICALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void MotiongTrackingApp::Render() {
main_scene_.Render(cur_pose);
}

void MotiongTrackingApp::FreeGLContent() { main_scene_.FreeGLContent(); }
void MotiongTrackingApp::DeleteResources() { main_scene_.DeleteResources(); }

std::string MotiongTrackingApp::GetPoseString() {
std::lock_guard<std::mutex> lock(pose_mutex_);
Expand Down
2 changes: 1 addition & 1 deletion motion-tracking-jni-example/app/src/main/jni/scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void Scene::InitGLContent() {
tango_gl::GestureCamera::CameraType::kThirdPerson);
}

void Scene::FreeGLContent() {
void Scene::DeleteResources() {
delete gesture_camera_;
delete axis_;
delete frustum_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class MotiongTrackingApp {
// Main render loop.
void Render();

// Release all OpenGL resources that allocate from the program.
void FreeGLContent();
// Release all resources that allocate from the program.
void DeleteResources();

// Retrun pose debug string.
std::string GetPoseString();
Expand Down
Loading

0 comments on commit 809c572

Please sign in to comment.