Skip to content

Commit

Permalink
Android fixed: Add fg/bg icons. Add FLAG_IMMUTABLE for intents. Disab…
Browse files Browse the repository at this point in the history
…le Billing stuff until it works. Upgrade build tools. Fix texture formats on simulator. Do not return temp.c_str() values.
  • Loading branch information
Hugh Sanderson committed Jan 28, 2024
1 parent dd6c4a7 commit 09a3577
Show file tree
Hide file tree
Showing 19 changed files with 213 additions and 61 deletions.
2 changes: 1 addition & 1 deletion project/src/android/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace nme {
jclass cls = FindClass("org/haxe/nme/GameActivity");
jmethodID mid = env->GetStaticMethodID(cls, "getClipboardText", "()Ljava/lang/String;");
if (mid == 0)
return std::string("").c_str();
return "";

jstring jPref = (jstring) env->CallStaticObjectMethod(cls, mid);
const char *c_ptr = env->GetStringUTFChars(jPref, 0);
Expand Down
6 changes: 3 additions & 3 deletions project/src/audio/OpenSlSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ class OpenSlDoubleBufferChannel : public OpenSlSourceChannel

void onBufferDone()
{
HxAtomicDec(&activeBuffers);
__sync_fetch_and_sub(&activeBuffers,1);
}


std::vector<unsigned char> &allocBuffer()
{
HxAtomicInc(&activeBuffers);
__sync_fetch_and_add(&activeBuffers,1);
LOG_SOUND("Writing to buffer %d/%d", writeBuffer, activeBuffers);
std::vector<unsigned char> & result = sampleBuffer[writeBuffer];
writeBuffer = !writeBuffer;
Expand Down Expand Up @@ -672,7 +672,7 @@ class OpenSlStreamChannel : public OpenSlDoubleBufferChannel

void onBufferDone()
{
HxAtomicDec(&activeBuffers);
__sync_fetch_and_sub(&activeBuffers,1);
LOG_SOUND("onBufferDone -> %d", activeBuffers);
if (!priming)
streamBuffer();
Expand Down
89 changes: 74 additions & 15 deletions project/src/opengl/OGLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

#define SWAP_RB 0

#if (defined(ANDROID_X86) || ( defined(ANDROID) && defined(HXCPP_M64) && !defined(HXCPP_ARM64)))
#define ANDROID_SIM
#endif

// 0xAARRGGBB
#if defined(ANDROID)
#ifdef ANDROID_X86
#ifdef ANDROID_SIM
#undef SWAP_RB
static bool SWAP_RB = false;
static bool SWAP_RB_MIP = false;
static bool sFormatChecked = false;
#endif
static int ARGB_STORE = GL_BGRA_EXT;
static int ARGB_PIXEL = GL_BGRA_EXT;
static int ARGB_STORE_MIP = GL_BGRA_EXT;
static int ARGB_PIXEL_MIP = GL_BGRA_EXT;
#elif defined(EMSCRIPTEN) || defined(RASPBERRYPI) || defined(GCW0)
#undef SWAP_RB
#define SWAP_RB 1
Expand Down Expand Up @@ -84,16 +91,18 @@ bool NonPO2Supported(bool inNotRepeating)
}


#ifdef ANDROID_X86
#ifdef ANDROID_SIM
void checkRgbFormat()
{
sFormatChecked = true;
char data[4];
char data[4*16*16];
glGetError();
GLuint tid = 0;
glGenTextures(1, &tid);
glBindTexture(GL_TEXTURE_2D,tid);
glTexImage2D(GL_TEXTURE_2D, 0, ARGB_STORE, 1, 1, 0, ARGB_PIXEL, GL_UNSIGNED_BYTE, data);


glTexImage2D(GL_TEXTURE_2D, 0, ARGB_STORE, 4, 4, 0, ARGB_PIXEL, GL_UNSIGNED_BYTE, data);
int err = glGetError();
if (err)
{
Expand All @@ -102,14 +111,32 @@ void checkRgbFormat()
ARGB_PIXEL = /*GL_BGRA*/ 0x80E1;

glTexImage2D(GL_TEXTURE_2D, 0, ARGB_STORE, 1, 1, 0, ARGB_PIXEL, GL_UNSIGNED_BYTE, data);

if (glGetError())
{
ELOG("Fall back to software colour transform");
ELOG("Fall back to software texture colour transform");
ARGB_STORE = GL_RGBA;
ARGB_PIXEL = GL_RGBA;
SWAP_RB = true;
}
}

ARGB_STORE_MIP = ARGB_STORE;
ARGB_PIXEL_MIP = ARGB_PIXEL;
SWAP_RB_MIP = SWAP_RB;


glTexImage2D(GL_TEXTURE_2D, 0, ARGB_STORE, 4, 4, 0, ARGB_PIXEL, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
err = glGetError();
if (err)
{
ELOG("Fall back to software texture colour transform for mipmaps");
ARGB_STORE_MIP = GL_RGBA;
ARGB_PIXEL_MIP = GL_RGBA;
SWAP_RB_MIP = true;
}

glDeleteTextures(1,&tid);
//else ELOG("Using normal texture format in simulator");
}
Expand All @@ -120,13 +147,20 @@ void checkRgbFormat()
// Type of storage.
// OGLES says this should match the pixel transfer type, but extensions allow
// the RGBA/BGRA swizzel to match the little-endian 4-byte layout
GLenum getTextureStorage(PixelFormat pixelFormat)
GLenum getTextureStorage(PixelFormat pixelFormat, bool mips)
{
switch(pixelFormat)
{
#ifdef ANDROID_SIM
case pfRGB: return gOglAllowRgb ? GL_RGB : mips ? ARGB_STORE_MIP : ARGB_STORE;
case pfBGRA: return mips ? ARGB_STORE_MIP : ARGB_STORE;
case pfBGRPremA: return mips ? ARGB_STORE_MIP : ARGB_STORE;
#else
case pfRGB: return gOglAllowRgb ? GL_RGB : ARGB_STORE;
case pfBGRA: return ARGB_STORE;
case pfBGRPremA: return ARGB_STORE;
#endif

case pfAlpha: return GL_ALPHA;
case pfARGB4444: return GL_RGBA; // GL_RGBA4
case pfRGB565: return GL_RGB;
Expand All @@ -151,13 +185,20 @@ GLenum getOglChannelType(PixelFormat pixelFormat)


// Transfer memory layout - in opengl enum
GLenum getTransferOgl(PixelFormat pixelFormat)
GLenum getTransferOgl(PixelFormat pixelFormat, bool mips)
{
switch(pixelFormat)
{
#ifdef ANDROID_SIM
case pfRGB: return gOglAllowRgb ? GL_RGB : mips ? ARGB_PIXEL_MIP : ARGB_PIXEL;
case pfBGRA: return mips ? ARGB_PIXEL_MIP : ARGB_PIXEL;
case pfBGRPremA: return mips ? ARGB_PIXEL_MIP : ARGB_PIXEL;
#else
case pfRGB: return gOglAllowRgb ? GL_RGB : ARGB_PIXEL;
case pfBGRA: return ARGB_PIXEL;
case pfBGRPremA: return ARGB_PIXEL;
#endif

case pfAlpha: return GL_ALPHA;
case pfARGB4444: return GL_UNSIGNED_SHORT_4_4_4_4;
case pfRGB565: return GL_UNSIGNED_SHORT_5_6_5;
Expand All @@ -169,7 +210,7 @@ GLenum getTransferOgl(PixelFormat pixelFormat)
}

// Gpu memory layout - in our enum, may need to swizzle
PixelFormat getTransferFormat(PixelFormat pixelFormat)
PixelFormat getTransferFormat(PixelFormat pixelFormat, bool mips)
{
switch(pixelFormat)
{
Expand All @@ -179,7 +220,11 @@ PixelFormat getTransferFormat(PixelFormat pixelFormat)
// Fallthough

case pfBGRA:
#ifdef ANDROID_SIM
return (mips ? SWAP_RB_MIP : SWAP_RB) ? pfRGBA :pfBGRA;
#else
return SWAP_RB ? pfRGBA :pfBGRA;
#endif

case pfLuma:
case pfAlpha:
Expand All @@ -190,7 +235,11 @@ PixelFormat getTransferFormat(PixelFormat pixelFormat)


case pfBGRPremA:
#ifdef ANDROID_SIM
return (mips ? SWAP_RB_MIP : SWAP_RB) ? pfRGBPremA :pfBGRPremA;
#else
return SWAP_RB ? pfRGBPremA :pfBGRPremA;
#endif

default: ;
}
Expand Down Expand Up @@ -221,7 +270,7 @@ class OGLTexture : public Texture
public:
OGLTexture(Surface *inSurface,unsigned int inFlags)
{
#ifdef ANDROID_X86
#ifdef ANDROID_SIM
if (!sFormatChecked)
checkRgbFormat();
#endif
Expand Down Expand Up @@ -255,11 +304,12 @@ class OGLTexture : public Texture
uint8 *buffer = 0;
PixelFormat fmt = mSurface->Format();

GLuint store_format = getTextureStorage(fmt);
GLuint pixel_format = getTransferOgl(fmt);
PixelFormat buffer_format = getTransferFormat(fmt);
GLuint store_format = getTextureStorage(fmt,mMipmaps);
GLuint pixel_format = getTransferOgl(fmt,mMipmaps);
PixelFormat buffer_format = getTransferFormat(fmt,mMipmaps);
GLenum channel= getOglChannelType(fmt);


int pw = BytesPerPixel(fmt);
int destPw = BytesPerPixel(buffer_format);

Expand Down Expand Up @@ -327,7 +377,16 @@ class OGLTexture : public Texture
glTexImage2D(GL_TEXTURE_2D, 0, store_format, mTextureWidth, mTextureHeight, 0, pixel_format, channel, buffer ? buffer : mSurface->GetBase());

if (mMipmaps)
{
glGetError();
glGenerateMipmap(GL_TEXTURE_2D);
int err = glGetError();
if (err)
{
ELOG("Error creating mipmaps @ %dx%d,%d/%d : %d\n", mTextureWidth, mTextureHeight, store_format,pixel_format, err);
mMipmaps = false;
}
}

mUploadedFormat = store_format;

Expand Down Expand Up @@ -372,7 +431,7 @@ class OGLTexture : public Texture
uint8 *buffer = 0;
PixelFormat fmt = mSurface->Format();

GLuint store_format = getTextureStorage(fmt);
GLuint store_format = getTextureStorage(fmt,mMipmaps);
if (store_format!=mUploadedFormat)
{
CreateTexture();
Expand All @@ -381,8 +440,8 @@ class OGLTexture : public Texture
{
glBindTexture(GL_TEXTURE_2D,mTextureID);

GLuint pixel_format = getTransferOgl(fmt);
PixelFormat buffer_format = getTransferFormat(fmt);
GLuint pixel_format = getTransferOgl(fmt,mMipmaps);
PixelFormat buffer_format = getTransferFormat(fmt,mMipmaps);
GLenum channel= getOglChannelType(fmt);

int pw = BytesPerPixel(fmt);
Expand Down
9 changes: 5 additions & 4 deletions templates/android/PROJ-gradle/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ apply plugin: 'com.google.firebase.crashlytics'


android {
namespace "::APP_PACKAGE::"

::if ANDROID_COMPILE_SDK_VERSION::
compileSdkVersion ::ANDROID_COMPILE_SDK_VERSION::
::else::
// This does not effect the output, only the gradle system and some warnings,
// so can be regularly updated
compileSdkVersion 28
compileSdkVersion 34
::end::

buildToolsVersion "28.0.3"
buildToolsVersion "34.0.0"
defaultConfig {
applicationId "::APP_PACKAGE::"
minSdkVersion ::ANDROID_MIN_API_LEVEL::
Expand Down Expand Up @@ -56,7 +58,6 @@ android {
// stack traces in the Crashlytics dashboard.
nativeSymbolUploadEnabled true

strippedNativeLibsDir "::NME_STRIPPED_ROOT::"
unstrippedNativeLibsDir "::NME_UNSTRIPPED_ROOT::"
}
::end::
Expand Down Expand Up @@ -93,7 +94,7 @@ dependencies {
})
// Support is in 'androidx.core' now
::if ANDROID_BILLING::
api 'com.android.billingclient:billing:2.1.0'
api 'com.android.billingclient:billing:6.0.1'
::end::
testImplementation 'junit:junit:4.12'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="::ANDROID_INSTALL_LOCATION::" package="::APP_PACKAGE::">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="::ANDROID_INSTALL_LOCATION::" >


<uses-feature android:glEsVersion="0x00020000" android:required="true" />
Expand All @@ -17,22 +17,22 @@
<application
android:label="::APP_TITLE::"
::if (DEBUGGABLE):: android:debuggable="true" ::end::
::if (HAS_ICON):: android:icon="@drawable/icon"::end::
::if (HAS_ICON):: android:icon="@mipmap/icon"::end::
::if (HAS_BANNER):: android:banner="@drawable/banner"::end::
::foreach appHeader:: ::__current__:: ::end::
>

<activity
android:name="MainActivity"
android:label="::APP_TITLE::"
android:exported="true"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"::if (WIN_ORIENTATION!=""):: android:screenOrientation="::WIN_ORIENTATION::"::end::
::foreach appActivity:: ::__current__:: ::end::
>

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="ouya.intent.category.GAME"/>
::foreach appIntent:: <category android:name="::__current__::"/> ::end::
</intent-filter>

Expand Down
8 changes: 4 additions & 4 deletions templates/android/PROJ-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ buildscript {
google()
}
dependencies {
classpath "com.android.tools.build:gradle:3.4.0"
classpath "com.android.tools.build:gradle:8.2.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

::if NME_FIREBASE::
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.gms:google-services:4.4.0'
::if NME_FIREBASE_PERFORMANCE::
// Add the dependency for the Performance Monitoring plugin
classpath 'com.google.firebase:perf-plugin:1.3.1' // Performance Monitoring plugin
//classpath 'com.google.firebase:perf-plugin:1.3.1' // Performance Monitoring plugin
::end::

::if NME_FIREBASE_CRASHLYTICS::
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
::end::
::end::
}
Expand Down
1 change: 1 addition & 0 deletions templates/android/PROJ-gradle/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.useAndroidX=true
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
2 changes: 1 addition & 1 deletion templates/android/PROJ/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="::ANDROID_INSTALL_LOCATION::" android:versionCode="::APP_BUILD_NUMBER::" android:versionName="::APP_VERSION::" package="::APP_PACKAGE::">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="::ANDROID_INSTALL_LOCATION::" android:versionCode="::APP_BUILD_NUMBER::" android:versionName="::APP_VERSION::" >

<application
android:label="::APP_TITLE::"
Expand Down
6 changes: 6 additions & 0 deletions templates/android/adaptive_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<adaptive-icon
xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/bg_icon"/>
<foreground android:drawable="@drawable/fg_icon"/>
</adaptive-icon>

4 changes: 2 additions & 2 deletions templates/android/extension-api/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.haxe.extension" >
<manifest >


</manifest>
</manifest>
Loading

0 comments on commit 09a3577

Please sign in to comment.