diff options
author | 2024-05-02 08:43:05 -0700 | |
---|---|---|
committer | 2024-05-02 09:02:43 -0700 | |
commit | e4a54a8ea7453434ec5c98998cd1d33cc3a9dee0 (patch) | |
tree | deac88cb9b24e13804262e16031b7d5d1d9b320d /ravenwood/runtime-helper-src | |
parent | 56be0b624a493f3e6127ffc4eebb9b110c187595 (diff) |
[Ravenwood] Start using HWUI native methods
Enable Matrix, Path and Interpolator for starters
Bug: 337110712
Bug: 337329128
Test: ./ravenwood/scripts/run-ravenwood-tests.sh
Test: atest CtsGraphicsTestCasesRavenwood
Test: atest CtsGraphicsTestCases
Change-Id: Iefa17f91837c5382067bf17fc148b158133a4de5
Diffstat (limited to 'ravenwood/runtime-helper-src')
-rw-r--r-- | ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java index 9057d163957e..96b7057d25ec 100644 --- a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java +++ b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java @@ -44,6 +44,14 @@ public class ClassLoadHook { public static final String LIBANDROID_RUNTIME_NAME = "android_runtime"; + /** + * Extra strings needed to pass to register_android_graphics_classes(). + * + * `android.graphics.Graphics` is not actually a class, so we can't use the same initialization + * strategy than the "normal" classes. So we just hardcode it here. + */ + public static final String GRAPHICS_EXTRA_INIT_PARAMS = ",android.graphics.Graphics"; + private static String sInitialDir = new File("").getAbsolutePath(); static { @@ -98,7 +106,6 @@ public class ClassLoadHook { private static void loadFrameworkNativeCode() { // This is called from class-initializers, so no synchronization is needed. if (sLoadFrameworkNativeCodeCalled) { - // This method has already been called before.s return; } sLoadFrameworkNativeCodeCalled = true; @@ -112,7 +119,8 @@ public class ClassLoadHook { } if (SKIP_LOADING_LIBANDROID) { - log("Skip loading " + LIBANDROID_RUNTIME_NAME); + log("Skip loading native runtime."); + return; } // Make sure these properties are not set. @@ -121,27 +129,39 @@ public class ClassLoadHook { ensurePropertyNotSet(KEYBOARD_PATHS); ensurePropertyNotSet(GRAPHICS_NATIVE_CLASSES); - // Tell libandroid what JNI to use. - final var jniClasses = getCoreNativeClassesToUse(); - if (jniClasses.isEmpty()) { - log("No classes require JNI methods, skip loading " + LIBANDROID_RUNTIME_NAME); + // Load the libraries, if needed. + final var libanrdoidClasses = getClassesWithNativeMethods(sLibandroidClasses); + final var libhwuiClasses = getClassesWithNativeMethods(sLibhwuiClasses); + if (libanrdoidClasses.isEmpty() && libhwuiClasses.isEmpty()) { + log("No classes require JNI methods, skip loading native runtime."); return; } - setProperty(CORE_NATIVE_CLASSES, jniClasses); - setProperty(GRAPHICS_NATIVE_CLASSES, ""); + setProperty(CORE_NATIVE_CLASSES, libanrdoidClasses); + setProperty(GRAPHICS_NATIVE_CLASSES, libhwuiClasses + GRAPHICS_EXTRA_INIT_PARAMS); + log("Loading " + LIBANDROID_RUNTIME_NAME + " for '" + libanrdoidClasses + "' and '" + + libhwuiClasses + "'"); RavenwoodUtils.loadJniLibrary(LIBANDROID_RUNTIME_NAME); } /** - * Classes with native methods that are backed by `libandroid_runtime`. + * Classes with native methods that are backed by libandroid_runtime. * - * At runtime, we check if these classes have any methods, and if so, we'll have - * `libandroid_runtime` register the native functions. + * See frameworks/base/core/jni/platform/host/HostRuntime.cpp */ - private static final Class<?>[] sClassesWithLibandroidNativeMethods = { + private static final Class<?>[] sLibandroidClasses = { android.util.Log.class, - android.os.Parcel.class, + }; + + /** + * Classes with native methods that are backed by libhwui. + * + * See frameworks/base/libs/hwui/apex/LayoutlibLoader.cpp + */ + private static final Class<?>[] sLibhwuiClasses = { + android.graphics.Interpolator.class, + android.graphics.Matrix.class, + android.graphics.Path.class, }; /** @@ -157,17 +177,15 @@ public class ClassLoadHook { } /** - * Create a list of classes as comma-separated that require JNI methods to be set up. - * - * <p>This list is used by frameworks/base/core/jni/LayoutlibLoader.cpp to decide - * what JNI methods to set up. + * Create a list of classes as comma-separated that require JNI methods to be set up from + * a given class list, ignoring classes with no native methods. */ - private static String getCoreNativeClassesToUse() { + private static String getClassesWithNativeMethods(Class<?>[] classes) { final var coreNativeClassesToLoad = new ArrayList<String>(); - for (var clazz : sClassesWithLibandroidNativeMethods) { + for (var clazz : classes) { if (hasNativeMethod(clazz)) { - log("Class %s has native methods", clazz); + log("Class %s has native methods", clazz.getCanonicalName()); coreNativeClassesToLoad.add(clazz.getName()); } } |