| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/app/android/child_process_service.h" | 5 #include "content/app/android/child_process_service.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 #include <cpu-features.h> | 8 #include <cpu-features.h> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/library_loader/library_loader_hooks.h" | 11 #include "base/android/library_loader/library_loader_hooks.h" |
| 12 #include "base/android/memory_pressure_listener_android.h" | 12 #include "base/android/memory_pressure_listener_android.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/posix/global_descriptors.h" | 14 #include "base/posix/global_descriptors.h" |
| 15 #include "content/child/child_thread.h" | 15 #include "content/child/child_thread.h" |
| 16 #include "content/common/android/surface_texture_lookup.h" |
| 16 #include "content/common/android/surface_texture_peer.h" | 17 #include "content/common/android/surface_texture_peer.h" |
| 17 #include "content/common/gpu/gpu_surface_lookup.h" | 18 #include "content/common/gpu/gpu_surface_lookup.h" |
| 18 #include "content/public/app/android_library_loader_hooks.h" | 19 #include "content/public/app/android_library_loader_hooks.h" |
| 19 #include "content/public/common/content_descriptors.h" | 20 #include "content/public/common/content_descriptors.h" |
| 20 #include "ipc/ipc_descriptors.h" | 21 #include "ipc/ipc_descriptors.h" |
| 21 #include "jni/ChildProcessService_jni.h" | 22 #include "jni/ChildProcessService_jni.h" |
| 22 #include "ui/gl/android/scoped_java_surface.h" | 23 #include "ui/gl/android/scoped_java_surface.h" |
| 23 | 24 |
| 24 using base::android::AttachCurrentThread; | 25 using base::android::AttachCurrentThread; |
| 25 using base::android::CheckException; | 26 using base::android::CheckException; |
| 26 using base::android::JavaIntArrayToIntVector; | 27 using base::android::JavaIntArrayToIntVector; |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 class SurfaceTexturePeerChildImpl : public content::SurfaceTexturePeer, | 33 class SurfaceTexturePeerChildImpl : public SurfaceTexturePeer, |
| 33 public content::GpuSurfaceLookup { | 34 public GpuSurfaceLookup, |
| 35 public SurfaceTextureLookup { |
| 34 public: | 36 public: |
| 35 // |service| is the instance of | 37 // |service| is the instance of |
| 36 // org.chromium.content.app.ChildProcessService. | 38 // org.chromium.content.app.ChildProcessService. |
| 37 explicit SurfaceTexturePeerChildImpl( | 39 explicit SurfaceTexturePeerChildImpl( |
| 38 const base::android::ScopedJavaLocalRef<jobject>& service) | 40 const base::android::ScopedJavaLocalRef<jobject>& service) |
| 39 : service_(service) { | 41 : service_(service) { |
| 40 GpuSurfaceLookup::InitInstance(this); | 42 GpuSurfaceLookup::InitInstance(this); |
| 43 SurfaceTextureLookup::InitInstance(this); |
| 41 } | 44 } |
| 42 | 45 |
| 43 virtual ~SurfaceTexturePeerChildImpl() { | 46 virtual ~SurfaceTexturePeerChildImpl() { |
| 44 GpuSurfaceLookup::InitInstance(NULL); | 47 GpuSurfaceLookup::InitInstance(NULL); |
| 48 SurfaceTextureLookup::InitInstance(NULL); |
| 45 } | 49 } |
| 46 | 50 |
| 51 // Overridden from SurfaceTexturePeer: |
| 47 virtual void EstablishSurfaceTexturePeer( | 52 virtual void EstablishSurfaceTexturePeer( |
| 48 base::ProcessHandle pid, | 53 base::ProcessHandle pid, |
| 49 scoped_refptr<gfx::SurfaceTexture> surface_texture, | 54 scoped_refptr<gfx::SurfaceTexture> surface_texture, |
| 50 int primary_id, | 55 int primary_id, |
| 51 int secondary_id) OVERRIDE { | 56 int secondary_id) OVERRIDE { |
| 52 JNIEnv* env = base::android::AttachCurrentThread(); | 57 JNIEnv* env = base::android::AttachCurrentThread(); |
| 53 content::Java_ChildProcessService_establishSurfaceTexturePeer( | 58 content::Java_ChildProcessService_establishSurfaceTexturePeer( |
| 54 env, service_.obj(), pid, | 59 env, service_.obj(), pid, |
| 55 surface_texture->j_surface_texture().obj(), primary_id, | 60 surface_texture->j_surface_texture().obj(), primary_id, |
| 56 secondary_id); | 61 secondary_id); |
| 57 CheckException(env); | 62 CheckException(env); |
| 58 } | 63 } |
| 59 | 64 |
| 65 // Overridden from GpuSurfaceLookup: |
| 60 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE { | 66 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE { |
| 61 JNIEnv* env = base::android::AttachCurrentThread(); | 67 JNIEnv* env = base::android::AttachCurrentThread(); |
| 62 gfx::ScopedJavaSurface surface( | 68 gfx::ScopedJavaSurface surface( |
| 63 content::Java_ChildProcessService_getViewSurface( | 69 content::Java_ChildProcessService_getViewSurface( |
| 64 env, service_.obj(), surface_id)); | 70 env, service_.obj(), surface_id)); |
| 65 | 71 |
| 66 if (surface.j_surface().is_null()) | 72 if (surface.j_surface().is_null()) |
| 67 return NULL; | 73 return NULL; |
| 68 | 74 |
| 69 ANativeWindow* native_window = ANativeWindow_fromSurface( | 75 ANativeWindow* native_window = ANativeWindow_fromSurface( |
| 70 env, surface.j_surface().obj()); | 76 env, surface.j_surface().obj()); |
| 71 | 77 |
| 72 return native_window; | 78 return native_window; |
| 73 } | 79 } |
| 74 | 80 |
| 81 // Overridden from SurfaceTextureLookup: |
| 82 virtual gfx::AcceleratedWidget AcquireNativeWidget(int primary_id, |
| 83 int secondary_id) |
| 84 OVERRIDE { |
| 85 JNIEnv* env = base::android::AttachCurrentThread(); |
| 86 gfx::ScopedJavaSurface surface( |
| 87 content::Java_ChildProcessService_getSurfaceTextureSurface( |
| 88 env, service_.obj(), primary_id, secondary_id)); |
| 89 |
| 90 if (surface.j_surface().is_null()) |
| 91 return NULL; |
| 92 |
| 93 ANativeWindow* native_window = |
| 94 ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
| 95 |
| 96 return native_window; |
| 97 } |
| 98 |
| 75 private: | 99 private: |
| 76 // The instance of org.chromium.content.app.ChildProcessService. | 100 // The instance of org.chromium.content.app.ChildProcessService. |
| 77 base::android::ScopedJavaGlobalRef<jobject> service_; | 101 base::android::ScopedJavaGlobalRef<jobject> service_; |
| 78 | 102 |
| 79 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); | 103 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); |
| 80 }; | 104 }; |
| 81 | 105 |
| 82 // Chrome actually uses the renderer code path for all of its child | 106 // Chrome actually uses the renderer code path for all of its child |
| 83 // processes such as renderers, plugins, etc. | 107 // processes such as renderers, plugins, etc. |
| 84 void InternalInitChildProcess(const std::vector<int>& file_ids, | 108 void InternalInitChildProcess(const std::vector<int>& file_ids, |
| 85 const std::vector<int>& file_fds, | 109 const std::vector<int>& file_fds, |
| 86 JNIEnv* env, | 110 JNIEnv* env, |
| 87 jclass clazz, | 111 jclass clazz, |
| 88 jobject context, | 112 jobject context, |
| 89 jobject service_in, | 113 jobject service_in, |
| 90 jint cpu_count, | 114 jint cpu_count, |
| 91 jlong cpu_features) { | 115 jlong cpu_features) { |
| 92 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); | 116 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); |
| 93 | 117 |
| 94 // Set the CPU properties. | 118 // Set the CPU properties. |
| 95 android_setCpu(cpu_count, cpu_features); | 119 android_setCpu(cpu_count, cpu_features); |
| 96 // Register the file descriptors. | 120 // Register the file descriptors. |
| 97 // This includes the IPC channel, the crash dump signals and resource related | 121 // This includes the IPC channel, the crash dump signals and resource related |
| 98 // files. | 122 // files. |
| 99 DCHECK(file_fds.size() == file_ids.size()); | 123 DCHECK(file_fds.size() == file_ids.size()); |
| 100 for (size_t i = 0; i < file_ids.size(); ++i) | 124 for (size_t i = 0; i < file_ids.size(); ++i) |
| 101 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 125 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
| 102 | 126 |
| 127 // SurfaceTexturePeerChildImpl implements the SurfaceTextureLookup interface, |
| 128 // which need to be set before we create a compositor thread that could be |
| 129 // using it to initialize resources. |
| 103 content::SurfaceTexturePeer::InitInstance( | 130 content::SurfaceTexturePeer::InitInstance( |
| 104 new SurfaceTexturePeerChildImpl(service)); | 131 new SurfaceTexturePeerChildImpl(service)); |
| 105 | 132 |
| 106 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 133 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
| 107 } | 134 } |
| 108 | 135 |
| 109 } // namespace <anonymous> | 136 } // namespace <anonymous> |
| 110 | 137 |
| 111 void InitChildProcess(JNIEnv* env, | 138 void InitChildProcess(JNIEnv* env, |
| 112 jclass clazz, | 139 jclass clazz, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 134 | 161 |
| 135 bool RegisterChildProcessService(JNIEnv* env) { | 162 bool RegisterChildProcessService(JNIEnv* env) { |
| 136 return RegisterNativesImpl(env); | 163 return RegisterNativesImpl(env); |
| 137 } | 164 } |
| 138 | 165 |
| 139 void ShutdownMainThread(JNIEnv* env, jobject obj) { | 166 void ShutdownMainThread(JNIEnv* env, jobject obj) { |
| 140 ChildThread::ShutdownThread(); | 167 ChildThread::ShutdownThread(); |
| 141 } | 168 } |
| 142 | 169 |
| 143 } // namespace content | 170 } // namespace content |
| OLD | NEW |