From 0997908c95151ce24609c10731990e648156b95d Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Tue, 19 Apr 2016 11:11:01 -0700 Subject: [PATCH] Move Vulkan layer path setup to ApplicationLoaders ThreadedRenderer was never the right place for this anyway, and ApplicationLoaders can provide both the full library search path (not just the extracted native library dir) as well as the application loader namespace. Bug: 28213888 Change-Id: Ibcc0a9178da4dba6f3f3105932fdac1a1d0261af --- core/java/android/app/ActivityThread.java | 4 -- core/java/android/app/ApplicationLoaders.java | 4 ++ core/java/android/view/ThreadedRenderer.java | 12 ----- core/jni/Android.mk | 1 + core/jni/AndroidRuntime.cpp | 2 + core/jni/android_app_ApplicationLoaders.cpp | 45 +++++++++++++++++++ core/jni/android_view_ThreadedRenderer.cpp | 16 ------- 7 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 core/jni/android_app_ApplicationLoaders.cpp diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index e54edf2a574b1..43238eceaffea 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -5205,10 +5205,6 @@ public final class ActivityThread { } else { Log.e(TAG, "Unable to setupGraphicsSupport due to missing code-cache directory"); } - - // Add the lib dir path to hardware renderer so that vulkan layers - // can be searched for within that directory. - ThreadedRenderer.setLibDir(data.info.getLibDir()); } // Install the Network Security Config Provider. This must happen before the application diff --git a/core/java/android/app/ApplicationLoaders.java b/core/java/android/app/ApplicationLoaders.java index d89e1864f36fd..c86994438096b 100644 --- a/core/java/android/app/ApplicationLoaders.java +++ b/core/java/android/app/ApplicationLoaders.java @@ -65,6 +65,8 @@ class ApplicationLoaders { Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); + setupVulkanLayerPath(pathClassloader, librarySearchPath); + mLoaders.put(zip, pathClassloader); return pathClassloader; } @@ -76,6 +78,8 @@ class ApplicationLoaders { } } + private static native void setupVulkanLayerPath(ClassLoader classLoader, String librarySearchPath); + /** * Adds a new path the classpath of the given loader. * @throws IllegalStateException if the provided class loader is not a {@link PathClassLoader}. diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java index 1cd2fb0ee96bf..e650d956915ac 100644 --- a/core/java/android/view/ThreadedRenderer.java +++ b/core/java/android/view/ThreadedRenderer.java @@ -251,17 +251,6 @@ public final class ThreadedRenderer { ThreadedRenderer.setupShadersDiskCache(new File(cacheDir, CACHE_PATH_SHADERS).getAbsolutePath()); } - /** - * Sets the library directory to use as a search path for vulkan layers. - * - * @param libDir A directory that contains vulkan layers - * - * @hide - */ - public static void setLibDir(String libDir) { - ThreadedRenderer.setupVulkanLayerPath(libDir); - } - /** * Creates a hardware renderer using OpenGL. * @@ -980,7 +969,6 @@ public final class ThreadedRenderer { } static native void setupShadersDiskCache(String cacheFile); - static native void setupVulkanLayerPath(String layerPath); private static native void nSetAtlas(long nativeProxy, GraphicBuffer buffer, long[] map); private static native void nSetProcessStatsBuffer(long nativeProxy, int fd); diff --git a/core/jni/Android.mk b/core/jni/Android.mk index 986a5fd722fe4..dd66b24a6b2f9 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -34,6 +34,7 @@ LOCAL_SRC_FILES:= \ com_google_android_gles_jni_EGLImpl.cpp \ com_google_android_gles_jni_GLImpl.cpp.arm \ android_app_Activity.cpp \ + android_app_ApplicationLoaders.cpp \ android_app_NativeActivity.cpp \ android_app_admin_SecurityLog.cpp \ android_opengl_EGL14.cpp \ diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index c2273d6f80b64..315887d954e51 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -181,6 +181,7 @@ extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env); extern int register_android_app_backup_FullBackup(JNIEnv *env); extern int register_android_app_Activity(JNIEnv *env); extern int register_android_app_ActivityThread(JNIEnv *env); +extern int register_android_app_ApplicationLoaders(JNIEnv *env); extern int register_android_app_NativeActivity(JNIEnv *env); extern int register_android_media_RemoteDisplay(JNIEnv *env); extern int register_android_util_jar_StrictJarFile(JNIEnv* env); @@ -1389,6 +1390,7 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_app_backup_FullBackup), REG_JNI(register_android_app_Activity), REG_JNI(register_android_app_ActivityThread), + REG_JNI(register_android_app_ApplicationLoaders), REG_JNI(register_android_app_NativeActivity), REG_JNI(register_android_util_jar_StrictJarFile), REG_JNI(register_android_view_InputChannel), diff --git a/core/jni/android_app_ApplicationLoaders.cpp b/core/jni/android_app_ApplicationLoaders.cpp new file mode 100644 index 0000000000000..24ee9591fc2f9 --- /dev/null +++ b/core/jni/android_app_ApplicationLoaders.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2016 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 +#include +#include + +#include "core_jni_helpers.h" + +static void setupVulkanLayerPath_native(JNIEnv* env, jobject clazz, + jobject classLoader, jstring librarySearchPath) { + ScopedUtfChars layerPathChars(env, librarySearchPath); + vulkan::LoaderData& loader_data = vulkan::LoaderData::GetInstance(); + loader_data.layer_path = layerPathChars.c_str(); + loader_data.app_namespace = android::FindNamespaceByClassLoader(env, classLoader); +} + +static const JNINativeMethod g_methods[] = { + { "setupVulkanLayerPath", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", + reinterpret_cast(setupVulkanLayerPath_native) }, +}; + +static const char* const kApplicationLoadersName = "android/app/ApplicationLoaders"; + +namespace android +{ + +int register_android_app_ApplicationLoaders(JNIEnv* env) { + return RegisterMethodsOrDie(env, kApplicationLoadersName, g_methods, NELEM(g_methods)); +} + +} // namespace android diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index 650a0fc82a7b8..5b4bfe96392c9 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -50,7 +49,6 @@ #include #include #include -#include namespace android { @@ -717,18 +715,6 @@ static void android_view_ThreadedRenderer_setupShadersDiskCache(JNIEnv* env, job env->ReleaseStringUTFChars(diskCachePath, cacheArray); } -// ---------------------------------------------------------------------------- -// Layers -// ---------------------------------------------------------------------------- - -static void android_view_ThreadedRenderer_setupVulkanLayerPath(JNIEnv* env, jobject clazz, - jstring layerPath) { - - const char* layerArray = env->GetStringUTFChars(layerPath, NULL); - vulkan::LoaderData::GetInstance().layer_path = layerArray; - env->ReleaseStringUTFChars(layerPath, layerArray); -} - // ---------------------------------------------------------------------------- // JNI Glue // ---------------------------------------------------------------------------- @@ -771,8 +757,6 @@ static const JNINativeMethod gMethods[] = { { "nDumpProfileData", "([BLjava/io/FileDescriptor;)V", (void*) android_view_ThreadedRenderer_dumpProfileData }, { "setupShadersDiskCache", "(Ljava/lang/String;)V", (void*) android_view_ThreadedRenderer_setupShadersDiskCache }, - { "setupVulkanLayerPath", "(Ljava/lang/String;)V", - (void*) android_view_ThreadedRenderer_setupVulkanLayerPath }, { "nAddRenderNode", "(JJZ)V", (void*) android_view_ThreadedRenderer_addRenderNode}, { "nRemoveRenderNode", "(JJ)V", (void*) android_view_ThreadedRenderer_removeRenderNode}, { "nDrawRenderNode", "(JJ)V", (void*) android_view_ThreadedRendererd_drawRenderNode},