| 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_impl.h" | 5 #include "content/app/android/child_process_service_impl.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/android/unguessable_token_android.h" | 13 #include "base/android/unguessable_token_android.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/posix/global_descriptors.h" | 17 #include "base/posix/global_descriptors.h" |
| 18 #include "base/unguessable_token.h" | 18 #include "base/unguessable_token.h" |
| 19 #include "content/child/child_thread_impl.h" | 19 #include "content/child/child_thread_impl.h" |
| 20 #include "content/public/common/content_descriptors.h" | 20 #include "content/public/common/content_descriptors.h" |
| 21 #include "gpu/ipc/common/android/android_overlay_provider_lookup.h" |
| 21 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" | 22 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" |
| 22 #include "gpu/ipc/common/android/surface_texture_peer.h" | 23 #include "gpu/ipc/common/android/surface_texture_peer.h" |
| 23 #include "gpu/ipc/common/gpu_surface_lookup.h" | 24 #include "gpu/ipc/common/gpu_surface_lookup.h" |
| 24 #include "ipc/ipc_descriptors.h" | 25 #include "ipc/ipc_descriptors.h" |
| 25 #include "jni/ChildProcessServiceImpl_jni.h" | 26 #include "jni/ChildProcessServiceImpl_jni.h" |
| 26 #include "ui/gl/android/scoped_java_surface.h" | 27 #include "ui/gl/android/scoped_java_surface.h" |
| 27 | 28 |
| 28 using base::android::AttachCurrentThread; | 29 using base::android::AttachCurrentThread; |
| 29 using base::android::CheckException; | 30 using base::android::CheckException; |
| 30 using base::android::JavaIntArrayToIntVector; | 31 using base::android::JavaIntArrayToIntVector; |
| 31 using base::android::JavaParamRef; | 32 using base::android::JavaParamRef; |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 // TODO(sievers): Use two different implementations of this depending on if | 38 // TODO(sievers): Use two different implementations of this depending on if |
| 38 // we're in a renderer or gpu process. | 39 // we're in a renderer or gpu process. |
| 39 class ChildProcessSurfaceManager : public gpu::SurfaceTexturePeer, | 40 class ChildProcessSurfaceManager : public gpu::SurfaceTexturePeer, |
| 40 public gpu::ScopedSurfaceRequestConduit, | 41 public gpu::ScopedSurfaceRequestConduit, |
| 41 public gpu::GpuSurfaceLookup { | 42 public gpu::GpuSurfaceLookup, |
| 43 public gpu::AndroidOverlayProviderLookup { |
| 42 public: | 44 public: |
| 43 ChildProcessSurfaceManager() {} | 45 ChildProcessSurfaceManager() {} |
| 44 ~ChildProcessSurfaceManager() override {} | 46 ~ChildProcessSurfaceManager() override {} |
| 45 | 47 |
| 46 // |service impl| is the instance of | 48 // |service impl| is the instance of |
| 47 // org.chromium.content.app.ChildProcessServiceImpl. | 49 // org.chromium.content.app.ChildProcessServiceImpl. |
| 48 void SetServiceImpl(const base::android::JavaRef<jobject>& service_impl) { | 50 void SetServiceImpl(const base::android::JavaRef<jobject>& service_impl) { |
| 49 service_impl_.Reset(service_impl); | 51 service_impl_.Reset(service_impl); |
| 50 } | 52 } |
| 51 | 53 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 97 } |
| 96 | 98 |
| 97 // Overridden from GpuSurfaceLookup: | 99 // Overridden from GpuSurfaceLookup: |
| 98 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override { | 100 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override { |
| 99 JNIEnv* env = base::android::AttachCurrentThread(); | 101 JNIEnv* env = base::android::AttachCurrentThread(); |
| 100 return gl::ScopedJavaSurface( | 102 return gl::ScopedJavaSurface( |
| 101 content::Java_ChildProcessServiceImpl_getViewSurface(env, service_impl_, | 103 content::Java_ChildProcessServiceImpl_getViewSurface(env, service_impl_, |
| 102 surface_id)); | 104 surface_id)); |
| 103 } | 105 } |
| 104 | 106 |
| 107 // Overridden from AndroidOverlayProviderLookup: |
| 108 base::android::ScopedJavaLocalRef<jobject> GetAndroidOverlayProvider() |
| 109 override { |
| 110 JNIEnv* env = base::android::AttachCurrentThread(); |
| 111 return Java_ChildProcessServiceImpl_getAndroidOverlayProvider( |
| 112 env, service_impl_.obj()); |
| 113 } |
| 114 |
| 105 private: | 115 private: |
| 106 friend struct base::DefaultLazyInstanceTraits<ChildProcessSurfaceManager>; | 116 friend struct base::DefaultLazyInstanceTraits<ChildProcessSurfaceManager>; |
| 107 // The instance of org.chromium.content.app.ChildProcessServiceImpl. | 117 // The instance of org.chromium.content.app.ChildProcessServiceImpl. |
| 108 base::android::ScopedJavaGlobalRef<jobject> service_impl_; | 118 base::android::ScopedJavaGlobalRef<jobject> service_impl_; |
| 109 | 119 |
| 110 DISALLOW_COPY_AND_ASSIGN(ChildProcessSurfaceManager); | 120 DISALLOW_COPY_AND_ASSIGN(ChildProcessSurfaceManager); |
| 111 }; | 121 }; |
| 112 | 122 |
| 113 static base::LazyInstance<ChildProcessSurfaceManager>::Leaky | 123 static base::LazyInstance<ChildProcessSurfaceManager>::Leaky |
| 114 g_child_process_surface_manager = LAZY_INSTANCE_INITIALIZER; | 124 g_child_process_surface_manager = LAZY_INSTANCE_INITIALIZER; |
| 115 | 125 |
| 116 // Chrome actually uses the renderer code path for all of its child | 126 // Chrome actually uses the renderer code path for all of its child |
| 117 // processes such as renderers, plugins, etc. | 127 // processes such as renderers, plugins, etc. |
| 118 void InternalInitChildProcessImpl(JNIEnv* env, | 128 void InternalInitChildProcessImpl(JNIEnv* env, |
| 119 const JavaParamRef<jobject>& service_impl, | 129 const JavaParamRef<jobject>& service_impl, |
| 120 jint cpu_count, | 130 jint cpu_count, |
| 121 jlong cpu_features) { | 131 jlong cpu_features) { |
| 122 // Set the CPU properties. | 132 // Set the CPU properties. |
| 123 android_setCpu(cpu_count, cpu_features); | 133 android_setCpu(cpu_count, cpu_features); |
| 124 | 134 |
| 125 g_child_process_surface_manager.Get().SetServiceImpl(service_impl); | 135 g_child_process_surface_manager.Get().SetServiceImpl(service_impl); |
| 126 | 136 |
| 127 gpu::SurfaceTexturePeer::InitInstance( | 137 gpu::SurfaceTexturePeer::InitInstance( |
| 128 g_child_process_surface_manager.Pointer()); | 138 g_child_process_surface_manager.Pointer()); |
| 129 gpu::GpuSurfaceLookup::InitInstance( | 139 gpu::GpuSurfaceLookup::InitInstance( |
| 130 g_child_process_surface_manager.Pointer()); | 140 g_child_process_surface_manager.Pointer()); |
| 131 gpu::ScopedSurfaceRequestConduit::SetInstance( | 141 gpu::ScopedSurfaceRequestConduit::SetInstance( |
| 132 g_child_process_surface_manager.Pointer()); | 142 g_child_process_surface_manager.Pointer()); |
| 143 gpu::AndroidOverlayProviderLookup::InitInstance( |
| 144 g_child_process_surface_manager.Pointer()); |
| 133 | 145 |
| 134 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 146 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
| 135 } | 147 } |
| 136 | 148 |
| 137 } // namespace <anonymous> | 149 } // namespace <anonymous> |
| 138 | 150 |
| 139 void RegisterGlobalFileDescriptor(JNIEnv* env, | 151 void RegisterGlobalFileDescriptor(JNIEnv* env, |
| 140 const JavaParamRef<jclass>& clazz, | 152 const JavaParamRef<jclass>& clazz, |
| 141 jint id, | 153 jint id, |
| 142 jint fd, | 154 jint fd, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 162 | 174 |
| 163 bool RegisterChildProcessServiceImpl(JNIEnv* env) { | 175 bool RegisterChildProcessServiceImpl(JNIEnv* env) { |
| 164 return RegisterNativesImpl(env); | 176 return RegisterNativesImpl(env); |
| 165 } | 177 } |
| 166 | 178 |
| 167 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 179 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 168 ChildThreadImpl::ShutdownThread(); | 180 ChildThreadImpl::ShutdownThread(); |
| 169 } | 181 } |
| 170 | 182 |
| 171 } // namespace content | 183 } // namespace content |
| OLD | NEW |