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/scoped_surface_request_conduit.h" | 21 #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/gpu_surface_lookup.h" | 22 #include "gpu/ipc/common/gpu_surface_lookup.h" |
24 #include "ipc/ipc_descriptors.h" | 23 #include "ipc/ipc_descriptors.h" |
25 #include "jni/ChildProcessServiceImpl_jni.h" | 24 #include "jni/ChildProcessServiceImpl_jni.h" |
26 #include "ui/gl/android/scoped_java_surface.h" | 25 #include "ui/gl/android/scoped_java_surface.h" |
| 26 #include "ui/gl/android/surface_texture.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. |
39 class ChildProcessSurfaceManager : public gpu::SurfaceTexturePeer, | 39 class ChildProcessSurfaceManager : public gpu::ScopedSurfaceRequestConduit, |
40 public gpu::ScopedSurfaceRequestConduit, | |
41 public gpu::GpuSurfaceLookup { | 40 public gpu::GpuSurfaceLookup { |
42 public: | 41 public: |
43 ChildProcessSurfaceManager() {} | 42 ChildProcessSurfaceManager() {} |
44 ~ChildProcessSurfaceManager() override {} | 43 ~ChildProcessSurfaceManager() override {} |
45 | 44 |
46 // |service impl| is the instance of | 45 // |service impl| is the instance of |
47 // org.chromium.content.app.ChildProcessServiceImpl. | 46 // org.chromium.content.app.ChildProcessServiceImpl. |
48 void SetServiceImpl(const base::android::JavaRef<jobject>& service_impl) { | 47 void SetServiceImpl(const base::android::JavaRef<jobject>& service_impl) { |
49 service_impl_.Reset(service_impl); | 48 service_impl_.Reset(service_impl); |
50 } | 49 } |
51 | 50 |
52 // Overridden from SurfaceTexturePeer: | |
53 void EstablishSurfaceTexturePeer( | |
54 base::ProcessHandle pid, | |
55 scoped_refptr<gl::SurfaceTexture> surface_texture, | |
56 int primary_id, | |
57 int secondary_id) override { | |
58 JNIEnv* env = base::android::AttachCurrentThread(); | |
59 content::Java_ChildProcessServiceImpl_establishSurfaceTexturePeer( | |
60 env, service_impl_, pid, surface_texture->j_surface_texture(), | |
61 primary_id, secondary_id); | |
62 } | |
63 | |
64 // Overriden from ScopedSurfaceRequestConduit: | 51 // Overriden from ScopedSurfaceRequestConduit: |
65 void ForwardSurfaceTextureForSurfaceRequest( | 52 void ForwardSurfaceTextureForSurfaceRequest( |
66 const base::UnguessableToken& request_token, | 53 const base::UnguessableToken& request_token, |
67 const gl::SurfaceTexture* surface_texture) override { | 54 const gl::SurfaceTexture* surface_texture) override { |
68 JNIEnv* env = base::android::AttachCurrentThread(); | 55 JNIEnv* env = base::android::AttachCurrentThread(); |
69 | 56 |
70 content:: | 57 content:: |
71 Java_ChildProcessServiceImpl_forwardSurfaceTextureForSurfaceRequest( | 58 Java_ChildProcessServiceImpl_forwardSurfaceTextureForSurfaceRequest( |
72 env, service_impl_, | 59 env, service_impl_, |
73 base::android::UnguessableTokenAndroid::Create(env, request_token), | 60 base::android::UnguessableTokenAndroid::Create(env, request_token), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // processes such as renderers, plugins, etc. | 104 // processes such as renderers, plugins, etc. |
118 void InternalInitChildProcessImpl(JNIEnv* env, | 105 void InternalInitChildProcessImpl(JNIEnv* env, |
119 const JavaParamRef<jobject>& service_impl, | 106 const JavaParamRef<jobject>& service_impl, |
120 jint cpu_count, | 107 jint cpu_count, |
121 jlong cpu_features) { | 108 jlong cpu_features) { |
122 // Set the CPU properties. | 109 // Set the CPU properties. |
123 android_setCpu(cpu_count, cpu_features); | 110 android_setCpu(cpu_count, cpu_features); |
124 | 111 |
125 g_child_process_surface_manager.Get().SetServiceImpl(service_impl); | 112 g_child_process_surface_manager.Get().SetServiceImpl(service_impl); |
126 | 113 |
127 gpu::SurfaceTexturePeer::InitInstance( | |
128 g_child_process_surface_manager.Pointer()); | |
129 gpu::GpuSurfaceLookup::InitInstance( | 114 gpu::GpuSurfaceLookup::InitInstance( |
130 g_child_process_surface_manager.Pointer()); | 115 g_child_process_surface_manager.Pointer()); |
131 gpu::ScopedSurfaceRequestConduit::SetInstance( | 116 gpu::ScopedSurfaceRequestConduit::SetInstance( |
132 g_child_process_surface_manager.Pointer()); | 117 g_child_process_surface_manager.Pointer()); |
133 | 118 |
134 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 119 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
135 } | 120 } |
136 | 121 |
137 } // namespace <anonymous> | 122 } // namespace <anonymous> |
138 | 123 |
(...skipping 23 matching lines...) Expand all Loading... |
162 | 147 |
163 bool RegisterChildProcessServiceImpl(JNIEnv* env) { | 148 bool RegisterChildProcessServiceImpl(JNIEnv* env) { |
164 return RegisterNativesImpl(env); | 149 return RegisterNativesImpl(env); |
165 } | 150 } |
166 | 151 |
167 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 152 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
168 ChildThreadImpl::ShutdownThread(); | 153 ChildThreadImpl::ShutdownThread(); |
169 } | 154 } |
170 | 155 |
171 } // namespace content | 156 } // namespace content |
OLD | NEW |