Skip to content

Commit

Permalink
Add support for Android 14 Developer Preview 1
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy committed Feb 9, 2023
1 parent 39ddedb commit 18d79c6
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 24 deletions.
13 changes: 13 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}
dependencies {
implementation 'dev.romainguy:pathway:0.10.0'
implementation 'dev.romainguy:pathway:0.11.0'
}
```

Expand Down Expand Up @@ -68,6 +68,11 @@ properly honor the path's fill type.

## Iterating over a Path

> **Note**
> As of Android 14 (tentatively API 34), iterating over a `Path` can be achieved using the new
> platform API [getPathIterator()](https://developer.android.com/reference/android/graphics/Path#getPathIterator()).
> Pathway is however compatible with Android 14, including Developer Preview builds.
With Pathway you can easily iterate over a `Path` object to inspect its segments
(curves or commands):

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ buildscript {
}

dependencies {
classpath "com.android.tools.build:gradle:7.3.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"
classpath "com.vanniktech:gradle-maven-publish-plugin:0.22.0"
classpath "com.android.tools.build:gradle:7.4.1"
classpath "com.vanniktech:gradle-maven-publish-plugin:0.24.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.7.20"
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=dev.romainguy
VERSION_NAME=0.10.0
VERSION_NAME=0.11.0

SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Oct 06 13:51:03 PDT 2022
#Thu Feb 09 09:14:05 PST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
8 changes: 4 additions & 4 deletions pathway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ group = GROUP
version = VERSION_NAME

android {
compileSdk 33
compileSdkPreview 'UpsideDownCake'
ndkVersion '25.1.8937393'

defaultConfig {
minSdk 21
targetSdk 33
targetSdk 34

externalNativeBuild {
cmake {
Expand Down Expand Up @@ -43,9 +43,9 @@ android {

dependencies {
androidTestImplementation 'androidx.core:core-ktx:1.9.0'
androidTestImplementation 'androidx.test:runner:1.5.1'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
}

apply plugin: "com.vanniktech.maven.publish"
37 changes: 30 additions & 7 deletions pathway/src/main/cpp/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef PATHWAY_PATH_H
#define PATHWAY_PATH_H

#include <cstddef>

#include <stdint.h>

// The following structures declare the minimum we need + a marker (generationId) to
Expand All @@ -26,13 +28,13 @@
// still exist but was moved after the data we need.

enum class Verb : uint8_t {
Move,
Line,
Quadratic,
Conic,
Cubic,
Close,
Done
Move = 0,
Line = 1,
Quadratic = 2,
Conic = 3,
Cubic = 4,
Close = 5,
Done = 6
};

struct Point {
Expand Down Expand Up @@ -115,6 +117,27 @@ struct PathRef30 {
__unused uint32_t generationId;
};

struct PathRef34 {
__unused int32_t refCount;
__unused float left;
__unused float top;
__unused float right;
__unused float bottom;
alignas(Point) __unused std::byte pointStorage[sizeof(Point) * 4];
Point* points;
__unused int pointSize;
__unused uint32_t pointCapacity;
alignas(Verb) __unused std::byte verbStorage[sizeof(Verb) * 4];
Verb* verbs;
int verbSize;
__unused int verbCapacity;
alignas(float) __unused std::byte conicStorage[sizeof(float) * 2];
float* conicWeights;
__unused int conicWeightsSize;
__unused int conicWeightsCapacity;
__unused uint32_t generationId;
};

struct Path {
PathRef21* pathRef;
};
Expand Down
23 changes: 18 additions & 5 deletions pathway/src/main/cpp/pathway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ std::once_flag sApiLevelOnceFlag;

static uint32_t api_level() {
std::call_once(sApiLevelOnceFlag, []() {
char sdkVersion[PROP_VALUE_MAX];
__system_property_get("ro.build.version.sdk", sdkVersion);
sApiLevel = atoi(sdkVersion); // NOLINT(cert-err34-c)
char buffer[PROP_VALUE_MAX];
__system_property_get("ro.build.version.sdk", buffer);
sApiLevel = atoi(buffer); // NOLINT(cert-err34-c)

// Adapt API level for Developer Preview builds
__system_property_get("ro.build.version.release_or_codename", buffer);
if (sApiLevel < 34 && !strcmp(buffer, "UpsideDownCake")) {
sApiLevel = 34;
}
});
return sApiLevel;
}

static jlong createPathIterator(JNIEnv* env, jobject,
static jlong createPathIterator(JNIEnv* env, jclass,
jobject path_, jint conicEvaluation_, jfloat tolerance_) {

auto nativePath = static_cast<intptr_t>(env->GetLongField(path_, sPath.nativePath));
Expand All @@ -60,7 +66,14 @@ static jlong createPathIterator(JNIEnv* env, jobject,
PathIterator::VerbDirection direction;

const uint32_t apiLevel = api_level();
if (apiLevel >= 30) {
if (apiLevel >= 33) {
auto* ref = reinterpret_cast<PathRef34*>(path->pathRef);
points = ref->points;
verbs = ref->verbs;
conicWeights = ref->conicWeights;
count = ref->verbSize;
direction = PathIterator::VerbDirection::Forward;
} else if (apiLevel >= 30) {
auto* ref = reinterpret_cast<PathRef30*>(path->pathRef);
points = ref->points;
verbs = ref->verbs;
Expand Down

0 comments on commit 18d79c6

Please sign in to comment.