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

Commit 4dc0aae6 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Replace framework usage of SkMatrix with a stable C API

Isolate the usage of SkMatrix within the graphics module and
replace external usages with a stable C API.

Bug: 137655431
Test: CTS presubmit
Change-Id: I058051a6afb4ae6d48ecdcf5cf8bd21aa0995e90
parent 88233e4c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1541,6 +1541,8 @@ public final class MotionEvent extends InputEvent implements Parcelable {
    @FastNative
    private static native float nativeGetAxisValue(long nativePtr,
            int axis, int pointerIndex, int historyPos);
    @FastNative
    private static native void nativeTransform(long nativePtr, Matrix matrix);

    // -------------- @CriticalNative ----------------------

@@ -1614,8 +1616,6 @@ public final class MotionEvent extends InputEvent implements Parcelable {

    @CriticalNative
    private static native void nativeScale(long nativePtr, float scale);
    @CriticalNative
    private static native void nativeTransform(long nativePtr, long matrix);

    private MotionEvent() {
    }
@@ -3210,7 +3210,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
            throw new IllegalArgumentException("matrix must not be null");
        }

        nativeTransform(mNativePtr, matrix.native_instance);
        nativeTransform(mNativePtr, matrix);
    }

    /**
+2 −1
Original line number Diff line number Diff line
@@ -345,8 +345,9 @@ cc_library_static {

    srcs: [
        "android/graphics/apex/android_bitmap.cpp",
        "android/graphics/apex/android_region.cpp",
        "android/graphics/apex/android_matrix.cpp",
        "android/graphics/apex/android_paint.cpp",
        "android/graphics/apex/android_region.cpp",

        "android_graphics_Canvas.cpp",
        "android_graphics_ColorSpace.cpp",
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
namespace android {

/* Gets the underlying SkMatrix from a Matrix object. */
extern SkMatrix* android_graphics_Matrix_getSkMatrix(JNIEnv* env, jobject matrixObj);
SkMatrix* android_graphics_Matrix_getSkMatrix(JNIEnv* env, jobject matrixObj);

} // namespace android

+37 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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 "android/graphics/matrix.h"
#include "Matrix.h"

bool AMatrix_getContents(JNIEnv* env, jobject matrixObj, float values[9]) {
    static_assert(SkMatrix::kMScaleX == 0, "SkMatrix unexpected index");
    static_assert(SkMatrix::kMSkewX ==  1, "SkMatrix unexpected index");
    static_assert(SkMatrix::kMTransX == 2, "SkMatrix unexpected index");
    static_assert(SkMatrix::kMSkewY ==  3, "SkMatrix unexpected index");
    static_assert(SkMatrix::kMScaleY == 4, "SkMatrix unexpected index");
    static_assert(SkMatrix::kMTransY == 5, "SkMatrix unexpected index");
    static_assert(SkMatrix::kMPersp0 == 6, "SkMatrix unexpected index");
    static_assert(SkMatrix::kMPersp1 == 7, "SkMatrix unexpected index");
    static_assert(SkMatrix::kMPersp2 == 8, "SkMatrix unexpected index");

    SkMatrix* m = android::android_graphics_Matrix_getSkMatrix(env, matrixObj);
    if (m != nullptr) {
        m->get9(values);
        return true;
    }
    return false;
}
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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.
 */

#ifndef ANDROID_GRAPHICS_MATRIX_H
#define ANDROID_GRAPHICS_MATRIX_H

#include <jni.h>
#include <sys/cdefs.h>

__BEGIN_DECLS

/**
 * Returns an array of floats that represents the 3x3 matrix of the java object.
 * @param values The 9 values of the 3x3 matrix in the following order.
 *               values[0] = scaleX  values[1] = skewX   values[2] = transX
 *               values[3] = skewY   values[4] = scaleY  values[5] = transY
 *               values[6] = persp0  values[7] = persp1  values[8] = persp2
 * @return true if the values param was populated and false otherwise.

 */
bool AMatrix_getContents(JNIEnv* env, jobject matrixObj, float values[9]);

__END_DECLS

#endif // ANDROID_GRAPHICS_MATRIX_H
Loading