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_manager.h" |
17 #include "content/common/android/surface_texture_peer.h" | 17 #include "content/common/android/surface_texture_peer.h" |
18 #include "content/common/gpu/gpu_surface_lookup.h" | 18 #include "content/common/gpu/gpu_surface_lookup.h" |
19 #include "content/public/app/android_library_loader_hooks.h" | 19 #include "content/public/app/android_library_loader_hooks.h" |
20 #include "content/public/common/content_descriptors.h" | 20 #include "content/public/common/content_descriptors.h" |
21 #include "ipc/ipc_descriptors.h" | 21 #include "ipc/ipc_descriptors.h" |
22 #include "jni/ChildProcessService_jni.h" | 22 #include "jni/ChildProcessService_jni.h" |
23 #include "ui/gl/android/scoped_java_surface.h" | 23 #include "ui/gl/android/scoped_java_surface.h" |
24 | 24 |
25 using base::android::AttachCurrentThread; | 25 using base::android::AttachCurrentThread; |
26 using base::android::CheckException; | 26 using base::android::CheckException; |
27 using base::android::JavaIntArrayToIntVector; | 27 using base::android::JavaIntArrayToIntVector; |
28 | 28 |
29 namespace content { | 29 namespace content { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 class SurfaceTexturePeerChildImpl : public SurfaceTexturePeer, | 33 // TODO(sievers): Use two different implementations of this depending on if |
34 public GpuSurfaceLookup, | 34 // we're in a renderer or gpu process. |
35 public SurfaceTextureLookup { | 35 class SurfaceTextureManagerImpl : public SurfaceTextureManager, |
36 public SurfaceTexturePeer, | |
37 public GpuSurfaceLookup { | |
36 public: | 38 public: |
37 // |service| is the instance of | 39 // |service| is the instance of |
38 // org.chromium.content.app.ChildProcessService. | 40 // org.chromium.content.app.ChildProcessService. |
39 explicit SurfaceTexturePeerChildImpl( | 41 explicit SurfaceTextureManagerImpl( |
40 const base::android::ScopedJavaLocalRef<jobject>& service) | 42 const base::android::ScopedJavaLocalRef<jobject>& service) |
41 : service_(service) { | 43 : service_(service) { |
44 SurfaceTexturePeer::InitInstance(this); | |
42 GpuSurfaceLookup::InitInstance(this); | 45 GpuSurfaceLookup::InitInstance(this); |
43 SurfaceTextureLookup::InitInstance(this); | 46 } |
47 virtual ~SurfaceTextureManagerImpl() { | |
48 SurfaceTexturePeer::InitInstance(NULL); | |
49 GpuSurfaceLookup::InitInstance(NULL); | |
44 } | 50 } |
45 | 51 |
46 virtual ~SurfaceTexturePeerChildImpl() { | 52 // Overridden from SurfaceTextureManager: |
47 GpuSurfaceLookup::InitInstance(NULL); | 53 virtual void RegisterSurfaceTexture( |
48 SurfaceTextureLookup::InitInstance(NULL); | 54 int surface_texture_id, |
55 int client_id, | |
56 gfx::SurfaceTexture* surface_texture) override { | |
57 JNIEnv* env = base::android::AttachCurrentThread(); | |
58 Java_ChildProcessService_createSurfaceTextureSurface( | |
no sievers
2014/10/09 19:31:40
Can you make this Java_ChildProcessService_registe
reveman
2014/10/10 02:25:19
Added a "release" call to the Java code as discuss
| |
59 env, | |
60 service_.obj(), | |
61 surface_texture_id, | |
62 client_id, | |
63 surface_texture->j_surface_texture().obj()); | |
64 DCHECK(!base::android::HasException(env)); | |
no sievers
2014/10/09 19:31:40
nit: doesn't the generated boilerplate already do
reveman
2014/10/10 02:25:19
Removed this and DCHECKs below.
| |
49 } | 65 } |
50 | 66 virtual void UnregisterSurfaceTexture(int surface_texture_id, |
51 // Overridden from SurfaceTexturePeer: | 67 int client_id) override { |
52 virtual void EstablishSurfaceTexturePeer( | |
53 base::ProcessHandle pid, | |
54 scoped_refptr<gfx::SurfaceTexture> surface_texture, | |
55 int primary_id, | |
56 int secondary_id) override { | |
57 JNIEnv* env = base::android::AttachCurrentThread(); | 68 JNIEnv* env = base::android::AttachCurrentThread(); |
58 content::Java_ChildProcessService_establishSurfaceTexturePeer( | 69 Java_ChildProcessService_destroySurfaceTextureSurface( |
59 env, service_.obj(), pid, | 70 env, service_.obj(), surface_texture_id, client_id); |
60 surface_texture->j_surface_texture().obj(), primary_id, | 71 DCHECK(!base::android::HasException(env)); |
61 secondary_id); | |
62 CheckException(env); | |
63 } | 72 } |
64 | 73 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_texture_id, |
65 // Overridden from GpuSurfaceLookup: | 74 int client_id) override { |
66 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override { | |
67 JNIEnv* env = base::android::AttachCurrentThread(); | 75 JNIEnv* env = base::android::AttachCurrentThread(); |
68 gfx::ScopedJavaSurface surface( | 76 gfx::ScopedJavaSurface surface( |
69 content::Java_ChildProcessService_getViewSurface( | 77 Java_ChildProcessService_getSurfaceTextureSurface( |
70 env, service_.obj(), surface_id)); | 78 env, service_.obj(), surface_texture_id, client_id)); |
79 DCHECK(!base::android::HasException(env)); | |
71 | 80 |
72 if (surface.j_surface().is_null()) | 81 if (surface.j_surface().is_null()) |
73 return NULL; | 82 return NULL; |
74 | 83 |
75 // Note: This ensures that any local references used by | 84 // Note: This ensures that any local references used by |
76 // ANativeWindow_fromSurface are released immediately. This is needed as a | 85 // ANativeWindow_fromSurface are released immediately. This is needed as a |
77 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 86 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
78 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 87 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
79 ANativeWindow* native_window = | 88 ANativeWindow* native_window = |
80 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | 89 ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
81 | 90 |
82 return native_window; | 91 return native_window; |
83 } | 92 } |
84 | 93 |
85 // Overridden from SurfaceTextureLookup: | 94 // Overridden from SurfaceTexturePeer: |
86 virtual gfx::AcceleratedWidget AcquireNativeWidget(int primary_id, | 95 virtual void EstablishSurfaceTexturePeer( |
87 int secondary_id) | 96 base::ProcessHandle pid, |
88 override { | 97 scoped_refptr<gfx::SurfaceTexture> surface_texture, |
98 int primary_id, | |
99 int secondary_id) override { | |
100 JNIEnv* env = base::android::AttachCurrentThread(); | |
101 content::Java_ChildProcessService_establishSurfaceTexturePeer( | |
102 env, | |
103 service_.obj(), | |
104 pid, | |
105 surface_texture->j_surface_texture().obj(), | |
106 primary_id, | |
107 secondary_id); | |
108 DCHECK(!base::android::HasException(env)); | |
109 } | |
110 | |
111 // Overridden from GpuSurfaceLookup: | |
112 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override { | |
89 JNIEnv* env = base::android::AttachCurrentThread(); | 113 JNIEnv* env = base::android::AttachCurrentThread(); |
90 gfx::ScopedJavaSurface surface( | 114 gfx::ScopedJavaSurface surface( |
91 content::Java_ChildProcessService_getSurfaceTextureSurface( | 115 content::Java_ChildProcessService_getViewSurface( |
92 env, service_.obj(), primary_id, secondary_id)); | 116 env, service_.obj(), surface_id)); |
117 DCHECK(!base::android::HasException(env)); | |
93 | 118 |
94 if (surface.j_surface().is_null()) | 119 if (surface.j_surface().is_null()) |
95 return NULL; | 120 return NULL; |
96 | 121 |
97 // Note: This ensures that any local references used by | 122 // Note: This ensures that any local references used by |
98 // ANativeWindow_fromSurface are released immediately. This is needed as a | 123 // ANativeWindow_fromSurface are released immediately. This is needed as a |
99 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 124 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
100 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 125 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
101 ANativeWindow* native_window = | 126 ANativeWindow* native_window = |
102 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | 127 ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
103 | 128 |
104 return native_window; | 129 return native_window; |
105 } | 130 } |
106 | 131 |
107 private: | 132 private: |
108 // The instance of org.chromium.content.app.ChildProcessService. | 133 // The instance of org.chromium.content.app.ChildProcessService. |
109 base::android::ScopedJavaGlobalRef<jobject> service_; | 134 base::android::ScopedJavaGlobalRef<jobject> service_; |
110 | 135 |
111 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); | 136 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl); |
112 }; | 137 }; |
113 | 138 |
114 // Chrome actually uses the renderer code path for all of its child | 139 // Chrome actually uses the renderer code path for all of its child |
115 // processes such as renderers, plugins, etc. | 140 // processes such as renderers, plugins, etc. |
116 void InternalInitChildProcess(const std::vector<int>& file_ids, | 141 void InternalInitChildProcess(const std::vector<int>& file_ids, |
117 const std::vector<int>& file_fds, | 142 const std::vector<int>& file_fds, |
118 JNIEnv* env, | 143 JNIEnv* env, |
119 jclass clazz, | 144 jclass clazz, |
120 jobject context, | 145 jobject context, |
121 jobject service_in, | 146 jobject service_in, |
122 jint cpu_count, | 147 jint cpu_count, |
123 jlong cpu_features) { | 148 jlong cpu_features) { |
124 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); | 149 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); |
125 | 150 |
126 // Set the CPU properties. | 151 // Set the CPU properties. |
127 android_setCpu(cpu_count, cpu_features); | 152 android_setCpu(cpu_count, cpu_features); |
128 // Register the file descriptors. | 153 // Register the file descriptors. |
129 // This includes the IPC channel, the crash dump signals and resource related | 154 // This includes the IPC channel, the crash dump signals and resource related |
130 // files. | 155 // files. |
131 DCHECK(file_fds.size() == file_ids.size()); | 156 DCHECK(file_fds.size() == file_ids.size()); |
132 for (size_t i = 0; i < file_ids.size(); ++i) | 157 for (size_t i = 0; i < file_ids.size(); ++i) |
133 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 158 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
134 | 159 |
135 // SurfaceTexturePeerChildImpl implements the SurfaceTextureLookup interface, | 160 SurfaceTextureManager::InitInstance(new SurfaceTextureManagerImpl(service)); |
136 // which need to be set before we create a compositor thread that could be | |
137 // using it to initialize resources. | |
138 content::SurfaceTexturePeer::InitInstance( | |
139 new SurfaceTexturePeerChildImpl(service)); | |
140 | 161 |
141 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 162 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
142 } | 163 } |
143 | 164 |
144 } // namespace <anonymous> | 165 } // namespace <anonymous> |
145 | 166 |
146 void InitChildProcess(JNIEnv* env, | 167 void InitChildProcess(JNIEnv* env, |
147 jclass clazz, | 168 jclass clazz, |
148 jobject context, | 169 jobject context, |
149 jobject service, | 170 jobject service, |
(...skipping 19 matching lines...) Expand all Loading... | |
169 | 190 |
170 bool RegisterChildProcessService(JNIEnv* env) { | 191 bool RegisterChildProcessService(JNIEnv* env) { |
171 return RegisterNativesImpl(env); | 192 return RegisterNativesImpl(env); |
172 } | 193 } |
173 | 194 |
174 void ShutdownMainThread(JNIEnv* env, jobject obj) { | 195 void ShutdownMainThread(JNIEnv* env, jobject obj) { |
175 ChildThread::ShutdownThread(); | 196 ChildThread::ShutdownThread(); |
176 } | 197 } |
177 | 198 |
178 } // namespace content | 199 } // namespace content |
OLD | NEW |