Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【igl nanovg part-1】Android : add seperate nanovg sample project #218

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// @fb-only

package com.facebook.igl.shell;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class NanovgSampleActivity extends SampleActivity implements View.OnClickListener {
private static String TAG = "NanovgSampleActivity";

@Override
protected void onCreate(Bundle icicle) {
mEnableStencilBuffer = true;

super.onCreate(icicle);

boolean hasCopy = getSharedPreferences("data", Context.MODE_PRIVATE).getBoolean("HasCopyAssets", false);

if (!hasCopy) {
copyAssetsDirToSDCard(this, "", getFilesDir().getAbsolutePath());

SharedPreferences.Editor editor = getSharedPreferences("data", Context.MODE_PRIVATE).edit();
editor.putBoolean("HasCopyAssets",true);
editor.commit();
}
}

public static void copyAssetsDirToSDCard(Context context, String assetsDirName, String sdCardPath) {
Log.d(TAG, "copyAssetsDirToSDCard() called with: context = [" + context + "], assetsDirName = [" + assetsDirName + "], sdCardPath = [" + sdCardPath + "]");
try {
String list[] = context.getAssets().list(assetsDirName);
if (list.length == 0) {
InputStream inputStream = context.getAssets().open(assetsDirName);
byte[] mByte = new byte[1024];
int bt = 0;
File file = new File(sdCardPath + File.separator
+ assetsDirName);
if (!file.exists()) {
file.createNewFile();
} else {
return;
}
FileOutputStream fos = new FileOutputStream(file);
while ((bt = inputStream.read(mByte)) != -1) {
fos.write(mByte, 0, bt);
}
fos.flush();
inputStream.close();
fos.close();
} else {
String subDirName = assetsDirName;
if (assetsDirName.contains("/")) {
subDirName = assetsDirName.substring(assetsDirName.lastIndexOf('/') + 1);
}
sdCardPath = sdCardPath + File.separator + subDirName;
File file = new File(sdCardPath);
if (!file.exists())
file.mkdirs();
for (String s : list) {
String fileName = assetsDirName.length() > 0 ? assetsDirName + File.separator + s : s;
copyAssetsDirToSDCard(context, fileName , sdCardPath);
}
}
} catch (
Exception e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class SampleActivity extends Activity implements View.OnClickListener {
private final int selectedTabColor = Color.BLUE;
private final int unSelectedTabColor = Color.GRAY;

protected boolean mEnableStencilBuffer = false;
vinsentli marked this conversation as resolved.
Show resolved Hide resolved

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
Expand Down Expand Up @@ -69,7 +71,7 @@ protected void onCreate(Bundle icicle) {
} else if (mConfigs[i].version.flavor == SampleLib.BackendFlavor.OpenGL_ES) {
backendView =
new SampleView(
getApplication(), mConfigs[i].version, mConfigs[i].swapchainColorTextureFormat);
getApplication(), mConfigs[i].version, mConfigs[i].swapchainColorTextureFormat, mEnableStencilBuffer);
((SampleView) backendView).onPause();
}

Expand Down
27 changes: 27 additions & 0 deletions build/android/nanovg/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="IGLNanovg"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.IGL"
tools:targetApi="33">
<activity
android:name=".NanovgSampleActivity"
android:configChanges="orientation|screenSize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
75 changes: 75 additions & 0 deletions build/android/nanovg/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

plugins {
id 'com.android.application'
}

android {
namespace 'com.facebook.igl.shell'
compileSdk 33

defaultConfig {
applicationId "com.facebook.igl.shell"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
ndk {
abiFilters 'arm64-v8a'
}
externalNativeBuild {
cmake {
cppFlags '-std=c++17'
}
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('../../../CMakeLists.txt')
version '3.22.1'
}
}
buildFeatures {
viewBinding true
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDir '../app/src/main/res/'

java.srcDir 'java'
java.srcDirs += ['../app/src/main/java/']

assets.srcDirs += ['../../../shell/resources/images', '../../../third-party/deps/src/nanovg/example/images', '../../../third-party/deps/src/nanovg/example']
}
}

ndkVersion '25.2.9519653'
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
1 change: 1 addition & 0 deletions build/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencyResolutionManagement {
}
rootProject.name = "IGL"
include ':app'
include ':nanovg'
include ':app-openxr-vulkan'
include ':app-openxr-gles'

Expand Down
Loading