Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be2187a1 authored by Doris Liu's avatar Doris Liu Committed by Android (Google) Code Review
Browse files

Merge "Add hooks in JNI to start using native path parsing"

parents ca596c6e cdd23f9d
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -27,22 +27,22 @@ public class PathParser {
    static final String LOGTAG = PathParser.class.getSimpleName();

    /**
     * @param pathData The string representing a path, the same as "d" string in svg file.
     * @param pathString The string representing a path, the same as "d" string in svg file.
     * @return the generated Path object.
     */
    public static Path createPathFromPathData(String pathData) {
    public static Path createPathFromPathData(String pathString) {
        if (pathString == null) {
            throw new IllegalArgumentException("Path string can not be null.");
        }
        Path path = new Path();
        PathDataNode[] nodes = createNodesFromPathData(pathData);
        if (nodes != null) {
            try {
                PathDataNode.nodesToPath(nodes, path);
            } catch (RuntimeException e) {
                throw new RuntimeException("Error in parsing " + pathData, e);
        boolean hasValidPathData = nParseStringForPath(path.mNativePath, pathString,
                pathString.length());
        if (!hasValidPathData) {
            throw new IllegalArgumentException("Path string: " + pathString +
                    " does not contain valid path data");
        }
        return path;
    }
        return null;
    }

    /**
     * @param pathData The string representing a path, the same as "d" string in svg file.
@@ -701,4 +701,7 @@ public class PathParser {
            }
        }
    }

    private static native boolean nParseStringForPath(long pathPtr, String pathString,
            int stringLength);
}
+1 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ LOCAL_SRC_FILES:= \
    android_util_Binder.cpp \
    android_util_EventLog.cpp \
    android_util_Log.cpp \
    android_util_PathParser.cpp \
    android_util_Process.cpp \
    android_util_StringBlock.cpp \
    android_util_XmlBlock.cpp \
+2 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ namespace android {
extern int register_android_content_AssetManager(JNIEnv* env);
extern int register_android_util_EventLog(JNIEnv* env);
extern int register_android_util_Log(JNIEnv* env);
extern int register_android_util_PathParser(JNIEnv* env);
extern int register_android_content_StringBlock(JNIEnv* env);
extern int register_android_content_XmlBlock(JNIEnv* env);
extern int register_android_graphics_Canvas(JNIEnv* env);
@@ -1300,6 +1301,7 @@ static const RegJNIRec gRegJNI[] = {
    REG_JNI(register_android_os_SystemClock),
    REG_JNI(register_android_util_EventLog),
    REG_JNI(register_android_util_Log),
    REG_JNI(register_android_util_PathParser),
    REG_JNI(register_android_content_AssetManager),
    REG_JNI(register_android_content_StringBlock),
    REG_JNI(register_android_content_XmlBlock),
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "jni.h"

#include <PathParser.h>
#include <SkPath.h>

#include "core_jni_helpers.h"

namespace android {

static bool parseStringForPath(JNIEnv* env, jobject, jlong skPathHandle, jstring inputPathStr,
        jint strLength) {
    const char* pathString = env->GetStringUTFChars(inputPathStr, NULL);
    SkPath* skPath = reinterpret_cast<SkPath*>(skPathHandle);
    bool hasValidData = android::uirenderer::PathParser::parseStringForSkPath(skPath, pathString,
            strLength);
    env->ReleaseStringUTFChars(inputPathStr, pathString);
    return hasValidData;
}

static const JNINativeMethod gMethods[] = {
    {"nParseStringForPath", "(JLjava/lang/String;I)Z", (void*)parseStringForPath}
};

int register_android_util_PathParser(JNIEnv* env) {
    return RegisterMethodsOrDie(env, "android/util/PathParser", gMethods, NELEM(gMethods));
}
};
+7 −1
Original line number Diff line number Diff line
@@ -183,10 +183,16 @@ void PathParser::dump(const PathData& data) {
    ALOGD("points are : %s", os.str().c_str());
}

void PathParser::parseStringForSkPath(SkPath* skPath, const char* pathStr, size_t strLen) {
bool PathParser::parseStringForSkPath(SkPath* skPath, const char* pathStr, size_t strLen) {
    PathData pathData;
    getPathDataFromString(&pathData, pathStr, strLen);

    // Check if there is valid data coming out of parsing the string.
    if (pathData.verbs.size() == 0) {
        return false;
    }
    VectorDrawablePath::verbsToPath(skPath, &pathData);
    return true;
}

}; // namespace uirenderer
Loading