OSDN Git Service

Move Vulkan layer path setup to ApplicationLoaders
authorDimitry Ivanov <dimitry@google.com>
Tue, 19 Apr 2016 18:11:01 +0000 (11:11 -0700)
committerJesse Hall <jessehall@google.com>
Thu, 12 May 2016 05:59:10 +0000 (22:59 -0700)
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
core/java/android/app/ApplicationLoaders.java
core/java/android/view/ThreadedRenderer.java
core/jni/Android.mk
core/jni/AndroidRuntime.cpp
core/jni/android_app_ApplicationLoaders.cpp [new file with mode: 0644]
core/jni/android_view_ThreadedRenderer.cpp

index e54edf2..43238ec 100644 (file)
@@ -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
index d89e186..c869944 100644 (file)
@@ -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}.
index 1cd2fb0..e650d95 100644 (file)
@@ -252,17 +252,6 @@ public final class ThreadedRenderer {
     }
 
     /**
-     * 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.
      *
      * @param translucent True if the surface is translucent, false otherwise
@@ -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);
index 986a5fd..dd66b24 100644 (file)
@@ -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 \
index c2273d6..315887d 100644 (file)
@@ -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 (file)
index 0000000..24ee959
--- /dev/null
@@ -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 <nativehelper/ScopedUtfChars.h>
+#include <nativeloader/native_loader.h>
+#include <vulkan/vulkan_loader_data.h>
+
+#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<void*>(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
index 650a0fc..5b4bfe9 100644 (file)
@@ -28,7 +28,6 @@
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
 #include <EGL/egl_cache.h>
-#include <vulkan/vulkan_loader_data.h>
 
 #include <utils/Looper.h>
 #include <utils/RefBase.h>
@@ -50,7 +49,6 @@
 #include <renderthread/RenderProxy.h>
 #include <renderthread/RenderTask.h>
 #include <renderthread/RenderThread.h>
-#include <Vector.h>
 
 namespace android {
 
@@ -718,18 +716,6 @@ static void android_view_ThreadedRenderer_setupShadersDiskCache(JNIEnv* env, job
 }
 
 // ----------------------------------------------------------------------------
-// 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},