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