Chromium Code Reviews| 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/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/posix/global_descriptors.h" | 17 #include "base/posix/global_descriptors.h" |
| 17 #include "base/unguessable_token.h" | 18 #include "base/unguessable_token.h" |
| 18 #include "content/child/child_thread_impl.h" | 19 #include "content/child/child_thread_impl.h" |
| 19 #include "content/public/common/content_descriptors.h" | 20 #include "content/public/common/content_descriptors.h" |
| 20 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" | 21 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" |
| 21 #include "gpu/ipc/common/android/surface_texture_manager.h" | |
| 22 #include "gpu/ipc/common/android/surface_texture_peer.h" | 22 #include "gpu/ipc/common/android/surface_texture_peer.h" |
| 23 #include "gpu/ipc/common/gpu_surface_lookup.h" | 23 #include "gpu/ipc/common/gpu_surface_lookup.h" |
| 24 #include "ipc/ipc_descriptors.h" | 24 #include "ipc/ipc_descriptors.h" |
| 25 #include "jni/ChildProcessServiceImpl_jni.h" | 25 #include "jni/ChildProcessServiceImpl_jni.h" |
| 26 #include "ui/gl/android/scoped_java_surface.h" | 26 #include "ui/gl/android/scoped_java_surface.h" |
| 27 | 27 |
| 28 using base::android::AttachCurrentThread; | 28 using base::android::AttachCurrentThread; |
| 29 using base::android::CheckException; | 29 using base::android::CheckException; |
| 30 using base::android::JavaIntArrayToIntVector; | 30 using base::android::JavaIntArrayToIntVector; |
| 31 using base::android::JavaParamRef; | 31 using base::android::JavaParamRef; |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // TODO(sievers): Use two different implementations of this depending on if | 37 // TODO(sievers): Use two different implementations of this depending on if |
| 38 // we're in a renderer or gpu process. | 38 // we're in a renderer or gpu process. |
|
ncarter (slow)
2016/12/01 23:20:08
Is this TODO still relevant?
tguilbert
2016/12/02 00:01:52
I am not 100% sure. I will leave it as is for the
| |
| 39 class SurfaceTextureManagerImpl : public gpu::SurfaceTextureManager, | 39 class ChildProcessSurfaceManager : public gpu::SurfaceTexturePeer, |
| 40 public gpu::SurfaceTexturePeer, | 40 public gpu::ScopedSurfaceRequestConduit, |
| 41 public gpu::ScopedSurfaceRequestConduit, | 41 public gpu::GpuSurfaceLookup { |
| 42 public gpu::GpuSurfaceLookup { | |
| 43 public: | 42 public: |
| 43 ChildProcessSurfaceManager() {} | |
| 44 ~ChildProcessSurfaceManager() override {} | |
| 45 | |
| 44 // |service impl| is the instance of | 46 // |service impl| is the instance of |
| 45 // org.chromium.content.app.ChildProcessServiceImpl. | 47 // org.chromium.content.app.ChildProcessServiceImpl. |
| 46 explicit SurfaceTextureManagerImpl( | 48 void SetServiceImpl(const base::android::JavaRef<jobject>& service_impl) { |
| 47 const base::android::JavaRef<jobject>& service_impl) | 49 service_impl_.Reset(service_impl); |
| 48 : service_impl_(service_impl) { | |
| 49 SurfaceTexturePeer::InitInstance(this); | |
| 50 gpu::GpuSurfaceLookup::InitInstance(this); | |
| 51 gpu::ScopedSurfaceRequestConduit::SetInstance(this); | |
| 52 } | |
| 53 ~SurfaceTextureManagerImpl() override { | |
| 54 SurfaceTexturePeer::InitInstance(NULL); | |
| 55 gpu::GpuSurfaceLookup::InitInstance(NULL); | |
| 56 gpu::ScopedSurfaceRequestConduit::SetInstance(nullptr); | |
| 57 } | |
| 58 | |
| 59 // Overridden from SurfaceTextureManager: | |
| 60 void RegisterSurfaceTexture(int surface_texture_id, | |
| 61 int client_id, | |
| 62 gl::SurfaceTexture* surface_texture) override { | |
| 63 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 64 Java_ChildProcessServiceImpl_createSurfaceTextureSurface( | |
| 65 env, service_impl_, surface_texture_id, client_id, | |
| 66 surface_texture->j_surface_texture()); | |
| 67 } | |
| 68 void UnregisterSurfaceTexture(int surface_texture_id, | |
| 69 int client_id) override { | |
| 70 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 71 Java_ChildProcessServiceImpl_destroySurfaceTextureSurface( | |
| 72 env, service_impl_, surface_texture_id, client_id); | |
| 73 } | |
| 74 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( | |
| 75 int surface_texture_id) override { | |
| 76 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 77 gl::ScopedJavaSurface surface( | |
| 78 Java_ChildProcessServiceImpl_getSurfaceTextureSurface( | |
| 79 env, service_impl_, surface_texture_id)); | |
| 80 | |
| 81 if (surface.j_surface().is_null()) | |
| 82 return NULL; | |
| 83 | |
| 84 // Note: This ensures that any local references used by | |
| 85 // ANativeWindow_fromSurface are released immediately. This is needed as a | |
| 86 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | |
| 87 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | |
| 88 ANativeWindow* native_window = | |
| 89 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | |
| 90 | |
| 91 return native_window; | |
| 92 } | 50 } |
| 93 | 51 |
| 94 // Overridden from SurfaceTexturePeer: | 52 // Overridden from SurfaceTexturePeer: |
| 95 void EstablishSurfaceTexturePeer( | 53 void EstablishSurfaceTexturePeer( |
| 96 base::ProcessHandle pid, | 54 base::ProcessHandle pid, |
| 97 scoped_refptr<gl::SurfaceTexture> surface_texture, | 55 scoped_refptr<gl::SurfaceTexture> surface_texture, |
| 98 int primary_id, | 56 int primary_id, |
| 99 int secondary_id) override { | 57 int secondary_id) override { |
| 100 JNIEnv* env = base::android::AttachCurrentThread(); | 58 JNIEnv* env = base::android::AttachCurrentThread(); |
| 101 content::Java_ChildProcessServiceImpl_establishSurfaceTexturePeer( | 59 content::Java_ChildProcessServiceImpl_establishSurfaceTexturePeer( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 | 96 |
| 139 // Overridden from GpuSurfaceLookup: | 97 // Overridden from GpuSurfaceLookup: |
| 140 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override { | 98 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override { |
| 141 JNIEnv* env = base::android::AttachCurrentThread(); | 99 JNIEnv* env = base::android::AttachCurrentThread(); |
| 142 return gl::ScopedJavaSurface( | 100 return gl::ScopedJavaSurface( |
| 143 content::Java_ChildProcessServiceImpl_getViewSurface(env, service_impl_, | 101 content::Java_ChildProcessServiceImpl_getViewSurface(env, service_impl_, |
| 144 surface_id)); | 102 surface_id)); |
| 145 } | 103 } |
| 146 | 104 |
| 147 private: | 105 private: |
| 106 friend struct base::DefaultLazyInstanceTraits<ChildProcessSurfaceManager>; | |
| 148 // The instance of org.chromium.content.app.ChildProcessServiceImpl. | 107 // The instance of org.chromium.content.app.ChildProcessServiceImpl. |
| 149 base::android::ScopedJavaGlobalRef<jobject> service_impl_; | 108 base::android::ScopedJavaGlobalRef<jobject> service_impl_; |
| 150 | 109 |
| 151 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl); | 110 DISALLOW_COPY_AND_ASSIGN(ChildProcessSurfaceManager); |
| 152 }; | 111 }; |
| 153 | 112 |
| 113 static base::LazyInstance<ChildProcessSurfaceManager>::Leaky | |
| 114 g_child_process_surface_manager = LAZY_INSTANCE_INITIALIZER; | |
| 115 | |
| 154 // Chrome actually uses the renderer code path for all of its child | 116 // Chrome actually uses the renderer code path for all of its child |
| 155 // processes such as renderers, plugins, etc. | 117 // processes such as renderers, plugins, etc. |
| 156 void InternalInitChildProcessImpl(JNIEnv* env, | 118 void InternalInitChildProcessImpl(JNIEnv* env, |
| 157 const JavaParamRef<jobject>& service_impl, | 119 const JavaParamRef<jobject>& service_impl, |
| 158 jint cpu_count, | 120 jint cpu_count, |
| 159 jlong cpu_features) { | 121 jlong cpu_features) { |
| 160 // Set the CPU properties. | 122 // Set the CPU properties. |
| 161 android_setCpu(cpu_count, cpu_features); | 123 android_setCpu(cpu_count, cpu_features); |
| 162 gpu::SurfaceTextureManager::SetInstance( | 124 |
| 163 new SurfaceTextureManagerImpl(service_impl)); | 125 g_child_process_surface_manager.Get().SetServiceImpl(service_impl); |
| 126 | |
| 127 gpu::SurfaceTexturePeer::InitInstance( | |
| 128 g_child_process_surface_manager.Pointer()); | |
| 129 gpu::GpuSurfaceLookup::InitInstance( | |
| 130 g_child_process_surface_manager.Pointer()); | |
| 131 gpu::ScopedSurfaceRequestConduit::SetInstance( | |
| 132 g_child_process_surface_manager.Pointer()); | |
| 164 | 133 |
| 165 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 134 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
| 166 } | 135 } |
| 167 | 136 |
| 168 } // namespace <anonymous> | 137 } // namespace <anonymous> |
| 169 | 138 |
| 170 void RegisterGlobalFileDescriptor(JNIEnv* env, | 139 void RegisterGlobalFileDescriptor(JNIEnv* env, |
| 171 const JavaParamRef<jclass>& clazz, | 140 const JavaParamRef<jclass>& clazz, |
| 172 jint id, | 141 jint id, |
| 173 jint fd, | 142 jint fd, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 193 | 162 |
| 194 bool RegisterChildProcessServiceImpl(JNIEnv* env) { | 163 bool RegisterChildProcessServiceImpl(JNIEnv* env) { |
| 195 return RegisterNativesImpl(env); | 164 return RegisterNativesImpl(env); |
| 196 } | 165 } |
| 197 | 166 |
| 198 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 167 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 199 ChildThreadImpl::ShutdownThread(); | 168 ChildThreadImpl::ShutdownThread(); |
| 200 } | 169 } |
| 201 | 170 |
| 202 } // namespace content | 171 } // namespace content |
| OLD | NEW |