Skip to content

Commit

Permalink
Reduce the size of the library
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy committed Dec 11, 2023
1 parent 2c5b207 commit d9d5985
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 41 deletions.
12 changes: 8 additions & 4 deletions 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.14.0'
implementation 'dev.romainguy:pathway:0.15.0'
}
```

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

## Iterating over a Path

> **Note**
> [!IMPORTANT]
> It is preferred to use the new androidx
> [graphics-path library](https://developer.android.com/jetpack/androidx/releases/graphic) to
> iterate over paths
> [!NOTE]
> As of Android 14 (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. You can also use the new androidx
> [graphics-path library](https://developer.android.com/jetpack/androidx/releases/graphics#graphics-path-1.0.0-alpha02).
> Pathway is however compatible with Android 14.
With Pathway you can easily iterate over a `Path` object to inspect its segments
(curves or commands):
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.14.0
VERSION_NAME=0.15.0

SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true
Expand Down
2 changes: 1 addition & 1 deletion pathway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {
}

dependencies {
androidTestImplementation 'androidx.core:core-ktx:1.10.1'
androidTestImplementation 'androidx.core:core-ktx:1.12.0'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
11 changes: 4 additions & 7 deletions pathway/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ add_library(
pathway.cpp
)

find_library(
log-lib
log
)

target_link_libraries(
set(VERSION_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/libpathway.map")
target_link_options(
pathway
${log-lib}
PRIVATE
"-Wl,--version-script=${VERSION_SCRIPT}"
)
6 changes: 6 additions & 0 deletions pathway/src/main/cpp/libpathway.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIBPATHWAY {
global:
JNI_OnLoad;
local:
*;
};
30 changes: 2 additions & 28 deletions pathway/src/main/cpp/pathway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,15 @@

#include <jni.h>

#include <sys/system_properties.h>

#include <mutex>
#include <android/api-level.h>

#define JNI_CLASS_NAME "dev/romainguy/graphics/path/Paths"

#if !defined(NDEBUG)
#include <android/log.h>
#define ANDROID_LOG_TAG "PathIterator"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, ANDROID_LOG_TAG, __VA_ARGS__)
#endif

struct {
jclass jniClass;
jfieldID nativePath;
} sPath{};

uint32_t sApiLevel = 0;
std::once_flag sApiLevelOnceFlag;

static uint32_t api_level() {
std::call_once(sApiLevelOnceFlag, []() {
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, jclass,
jobject path_, jint conicEvaluation_, jfloat tolerance_) {

Expand All @@ -65,7 +39,7 @@ static jlong createPathIterator(JNIEnv* env, jclass,
int count;
PathIterator::VerbDirection direction;

const uint32_t apiLevel = api_level();
const uint32_t apiLevel = android_get_device_api_level();
if (apiLevel >= 34) {
auto* ref = reinterpret_cast<PathRef34*>(path->pathRef);
points = ref->points;
Expand Down

0 comments on commit d9d5985

Please sign in to comment.