From 377c4b36180daafaa03fb5225af4e09f9cd65e2c Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sun, 26 Nov 2023 01:42:07 +0200 Subject: [PATCH 1/2] Android CI (#3) * Create Android_Build.yml * Fix Android workflow name * Deepfried * Setup Java for Android CI * Add arm64 Android CI * Add ARMv8.1 + crypto minimum to Android CI * https://www.youtube.com/watch?v=Ku5fgOHy1JY --- .github/workflows/Android_Build.yml | 89 +++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .github/workflows/Android_Build.yml diff --git a/.github/workflows/Android_Build.yml b/.github/workflows/Android_Build.yml new file mode 100644 index 00000000..c94140d7 --- /dev/null +++ b/.github/workflows/Android_Build.yml @@ -0,0 +1,89 @@ +name: Android Build + +on: + push: + branches: + - master + pull_request: + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + x64: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Fetch submodules + run: git submodule update --init --recursive + + - name: Setup Vulkan SDK + uses: humbletim/setup-vulkan-sdk@v1.2.0 + with: + vulkan-query-version: latest + vulkan-use-cache: true + vulkan-components: Vulkan-Headers, Vulkan-Loader, SPIRV-Tools, Glslang + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'zulu' # See 'Supported distributions' for available options + java-version: '17' + + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DBUILD_HYDRA_CORE=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86_64 -DENABLE_VULKAN=0 + + - name: Build + run: | + cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + mv ./build/libAlber.so ./src/pandroid/app/src/main/jniLibs/x86_64/ + cd src/pandroid + ./gradlew assembleDebug + cd ../.. + + - name: Upload executable + uses: actions/upload-artifact@v2 + with: + name: Android APK (x86-64) + path: './src/pandroid/app/build/outputs/apk/debug/app-debug.apk' + + arm64: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Fetch submodules + run: git submodule update --init --recursive + + - name: Setup Vulkan SDK + uses: humbletim/setup-vulkan-sdk@v1.2.0 + with: + vulkan-query-version: latest + vulkan-use-cache: true + vulkan-components: Vulkan-Headers, Vulkan-Loader, SPIRV-Tools, Glslang + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: 'zulu' # See 'Supported distributions' for available options + java-version: '17' + + - name: Configure CMake + run: cmake -B ${{github.workspace}}/build -DBUILD_HYDRA_CORE=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DENABLE_VULKAN=0 -DCMAKE_CXX_FLAGS="-march=armv8.1-a+crypto" + + - name: Build + run: | + cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + mv ./build/libAlber.so ./src/pandroid/app/src/main/jniLibs/arm64-v8a/ + cd src/pandroid + ./gradlew assembleDebug + cd ../.. + + - name: Upload executable + uses: actions/upload-artifact@v2 + with: + name: Android APK (arm64) + path: './src/pandroid/app/build/outputs/apk/debug/app-debug.apk' + From fea8862fb171d537b023e27f7417896b435d25c4 Mon Sep 17 00:00:00 2001 From: Gabriel Machado <97042217+GabrielBRDeveloper@users.noreply.github.com> Date: Sun, 26 Nov 2023 16:18:25 -0400 Subject: [PATCH 2/2] Fixed Errors. (#2) * - Fix MainActivity.java crash on start. - Separate MainActivity.java into two Classes: MainActivity.java and GameActivity - Implement post callback in GLRenderer. * . --- src/pandroid/app/src/main/AndroidManifest.xml | 14 ++++-- .../panda3ds/pandroid/PandaGlSurfaceView.java | 19 ------- .../panda3ds/pandroid/app/BaseActivity.java | 6 +++ .../panda3ds/pandroid/app/GameActivity.java | 32 ++++++++++++ .../pandroid/{ => app}/MainActivity.java | 49 +++++++------------ .../panda3ds/pandroid/utils/Constants.java | 6 +++ .../pandroid/{ => utils}/PathUtils.java | 2 +- .../pandroid/{ => view}/PandaGlRenderer.java | 20 +++++--- .../pandroid/view/PandaGlSurfaceView.java | 20 ++++++++ .../app/src/main/res/layout/activity_main.xml | 26 +++++----- .../app/src/main/res/values/strings.xml | 1 + 11 files changed, 123 insertions(+), 72 deletions(-) delete mode 100644 src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlSurfaceView.java create mode 100644 src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/BaseActivity.java create mode 100644 src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java rename src/pandroid/app/src/main/java/com/panda3ds/pandroid/{ => app}/MainActivity.java (52%) create mode 100644 src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java rename src/pandroid/app/src/main/java/com/panda3ds/pandroid/{ => utils}/PathUtils.java (99%) rename src/pandroid/app/src/main/java/com/panda3ds/pandroid/{ => view}/PandaGlRenderer.java (90%) create mode 100644 src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java diff --git a/src/pandroid/app/src/main/AndroidManifest.xml b/src/pandroid/app/src/main/AndroidManifest.xml index 0effd35f..2d318370 100644 --- a/src/pandroid/app/src/main/AndroidManifest.xml +++ b/src/pandroid/app/src/main/AndroidManifest.xml @@ -2,6 +2,12 @@ + + + + - + + - \ No newline at end of file diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlSurfaceView.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlSurfaceView.java deleted file mode 100644 index 657b327c..00000000 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlSurfaceView.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.panda3ds.pandroid; - -import android.app.Activity; -import android.content.Context; -import android.opengl.GLSurfaceView; -import android.util.DisplayMetrics; - -import com.panda3ds.pandroid.PandaGlRenderer; - -public class PandaGlSurfaceView extends GLSurfaceView { - final PandaGlRenderer renderer; - - public PandaGlSurfaceView(Context context) { - super(context); - setEGLContextClientVersion(3); - renderer = new PandaGlRenderer(); - setRenderer(renderer); - } -} \ No newline at end of file diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/BaseActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/BaseActivity.java new file mode 100644 index 00000000..597d664b --- /dev/null +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/BaseActivity.java @@ -0,0 +1,6 @@ +package com.panda3ds.pandroid.app; + +import androidx.appcompat.app.AppCompatActivity; + +public class BaseActivity extends AppCompatActivity { +} diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java new file mode 100644 index 00000000..70750d2c --- /dev/null +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java @@ -0,0 +1,32 @@ +package com.panda3ds.pandroid.app; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.FrameLayout; +import android.widget.Toast; + +import androidx.annotation.Nullable; + +import com.panda3ds.pandroid.utils.Constants; +import com.panda3ds.pandroid.view.PandaGlSurfaceView; + +public class GameActivity extends BaseActivity { + private PandaGlSurfaceView pandaSurface; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Intent intent = getIntent(); + if(!intent.hasExtra(Constants.EXTRA_PATH)){ + + setContentView(new FrameLayout(this)); + Toast.makeText(this, "INVALID ROM PATH", Toast.LENGTH_LONG).show(); + finish(); + return; + } + + pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));; + setContentView(pandaSurface); + } +} diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/MainActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/MainActivity.java similarity index 52% rename from src/pandroid/app/src/main/java/com/panda3ds/pandroid/MainActivity.java rename to src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/MainActivity.java index b7b3726d..616daf13 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/MainActivity.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/MainActivity.java @@ -1,24 +1,20 @@ -package com.panda3ds.pandroid; +package com.panda3ds.pandroid.app; -import androidx.appcompat.app.AppCompatActivity; import static android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION; import android.content.Intent; import android.os.Build; import android.os.Bundle; -import android.view.WindowInsets; -import android.view.View; import android.os.Environment; import android.widget.Toast; -import android.widget.FrameLayout; -import com.panda3ds.pandroid.PathUtils; -import com.google.android.material.floatingactionbutton.FloatingActionButton; +import androidx.appcompat.app.AppCompatActivity; + +import com.panda3ds.pandroid.utils.Constants; +import com.panda3ds.pandroid.R; +import com.panda3ds.pandroid.utils.PathUtils; public class MainActivity extends AppCompatActivity { - - PandaGlSurfaceView glView; - private static final int PICK_3DS_ROM = 2; private void openFile() { @@ -31,22 +27,18 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (!Environment.isExternalStorageManager()) { - Intent intent = new Intent(ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); - startActivity(intent); - } - - glView = new PandaGlSurfaceView(this); - setContentView(glView); - FloatingActionButton fab = new FloatingActionButton(this); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - openFile(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (!Environment.isExternalStorageManager()) { + Intent intent = new Intent(ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); + startActivity(intent); } + } + + setContentView(R.layout.activity_main); + + findViewById(R.id.load_rom).setOnClickListener(v->{ + openFile(); }); - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(200, 200); - addContentView(fab, params); } @Override @@ -55,13 +47,10 @@ public class MainActivity extends AppCompatActivity { if (resultCode == RESULT_OK) { String path = PathUtils.getPath(getApplicationContext(), data.getData()); Toast.makeText(getApplicationContext(), "pandroid opening " + path, Toast.LENGTH_LONG).show(); - glView.queueEvent(new Runnable() { - @Override - public void run() { - AlberDriver.LoadRom(path); - } - }); + startActivity(new Intent(this, GameActivity.class) + .putExtra(Constants.EXTRA_PATH, path)); } + super.onActivityResult(requestCode, resultCode, data); } } } \ No newline at end of file diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java new file mode 100644 index 00000000..b4cf805e --- /dev/null +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java @@ -0,0 +1,6 @@ +package com.panda3ds.pandroid.utils; + +public class Constants { + public static final String EXTRA_PATH = "path"; + public static final String LOG_TAG = "Alber"; +} diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/PathUtils.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/PathUtils.java similarity index 99% rename from src/pandroid/app/src/main/java/com/panda3ds/pandroid/PathUtils.java rename to src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/PathUtils.java index 740223eb..0a24603c 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/PathUtils.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/PathUtils.java @@ -1,4 +1,4 @@ -package com.panda3ds.pandroid; +package com.panda3ds.pandroid.utils; import android.content.ContentUris; import android.content.Context; diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlRenderer.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java similarity index 90% rename from src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlRenderer.java rename to src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java index cb6f90da..3cf5407f 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/PandaGlRenderer.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlRenderer.java @@ -1,4 +1,4 @@ -package com.panda3ds.pandroid; +package com.panda3ds.pandroid.view; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -7,22 +7,25 @@ import static android.opengl.GLES32.*; import android.content.res.Resources; import android.opengl.GLSurfaceView; -import android.util.DisplayMetrics; import android.util.Log; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; +import com.panda3ds.pandroid.AlberDriver; + +import java.util.ArrayList; public class PandaGlRenderer implements GLSurfaceView.Renderer { + + private final String romPath; int screenWidth, screenHeight; int screenTexture; public int screenFbo; - PandaGlRenderer() { + PandaGlRenderer(String romPath) { super(); + this.romPath = romPath; } + @Override protected void finalize() throws Throwable { if (screenTexture != 0) { @@ -33,7 +36,7 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer { } super.finalize(); } - + public void onSurfaceCreated(GL10 unused, EGLConfig config) { Log.i("pandroid", glGetString(GL_EXTENSIONS)); Log.w("pandroid", glGetString(GL_VERSION)); @@ -59,6 +62,7 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer { glBindFramebuffer(GL_FRAMEBUFFER, 0); AlberDriver.Initialize(); + AlberDriver.LoadRom(romPath); } public void onDrawFrame(GL10 unused) { @@ -76,4 +80,4 @@ public class PandaGlRenderer implements GLSurfaceView.Renderer { screenHeight = height; glDisable(GL_SCISSOR_TEST); } -} +} \ No newline at end of file diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java new file mode 100644 index 00000000..35805657 --- /dev/null +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/view/PandaGlSurfaceView.java @@ -0,0 +1,20 @@ +package com.panda3ds.pandroid.view; + +import android.content.Context; +import android.opengl.GLSurfaceView; + +public class PandaGlSurfaceView extends GLSurfaceView { + final PandaGlRenderer renderer; + + public PandaGlSurfaceView(Context context, String romPath) { + super(context); + setEGLContextClientVersion(3); + setDebugFlags(DEBUG_LOG_GL_CALLS); + renderer = new PandaGlRenderer(romPath); + setRenderer(renderer); + } + + public PandaGlRenderer getRenderer() { + return renderer; + } +} \ No newline at end of file diff --git a/src/pandroid/app/src/main/res/layout/activity_main.xml b/src/pandroid/app/src/main/res/layout/activity_main.xml index 17eab17b..89a17ce9 100644 --- a/src/pandroid/app/src/main/res/layout/activity_main.xml +++ b/src/pandroid/app/src/main/res/layout/activity_main.xml @@ -1,18 +1,22 @@ - + tools:context=".app.MainActivity"> - + +