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_peer.h" | 17 #include "content/common/android/surface_texture_peer.h" |
17 #include "content/common/gpu/gpu_surface_lookup.h" | 18 #include "content/common/gpu/gpu_surface_lookup.h" |
18 #include "content/public/app/android_library_loader_hooks.h" | 19 #include "content/public/app/android_library_loader_hooks.h" |
19 #include "content/public/common/content_descriptors.h" | 20 #include "content/public/common/content_descriptors.h" |
20 #include "ipc/ipc_descriptors.h" | 21 #include "ipc/ipc_descriptors.h" |
21 #include "jni/ChildProcessService_jni.h" | 22 #include "jni/ChildProcessService_jni.h" |
22 #include "ui/gl/android/scoped_java_surface.h" | 23 #include "ui/gl/android/scoped_java_surface.h" |
23 | 24 |
24 using base::android::AttachCurrentThread; | 25 using base::android::AttachCurrentThread; |
25 using base::android::CheckException; | 26 using base::android::CheckException; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 return native_window; | 73 return native_window; |
73 } | 74 } |
74 | 75 |
75 private: | 76 private: |
76 // The instance of org.chromium.content.app.ChildProcessService. | 77 // The instance of org.chromium.content.app.ChildProcessService. |
77 base::android::ScopedJavaGlobalRef<jobject> service_; | 78 base::android::ScopedJavaGlobalRef<jobject> service_; |
78 | 79 |
79 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); | 80 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); |
80 }; | 81 }; |
81 | 82 |
83 class SurfaceTextureLookupChildImpl : public content::SurfaceTextureLookup { | |
84 public: | |
85 // |service| is the instance of | |
86 // org.chromium.content.app.ChildProcessService. | |
87 explicit SurfaceTextureLookupChildImpl( | |
88 const base::android::ScopedJavaLocalRef<jobject>& service) | |
no sievers
2014/03/14 01:24:51
Do you maybe just fold this into the existing Surf
reveman
2014/03/14 19:44:53
To fold this into the above class I'd like to merg
no sievers
2014/03/18 20:58:12
For the view surface lookup, it's slightly differe
| |
89 : service_(service) {} | |
90 | |
91 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_texture_id) | |
92 OVERRIDE { | |
93 JNIEnv* env = base::android::AttachCurrentThread(); | |
94 gfx::ScopedJavaSurface surface( | |
95 content::Java_ChildProcessService_getSurfaceTextureSurface( | |
96 env, service_.obj(), surface_texture_id)); | |
97 | |
98 if (surface.j_surface().is_null()) | |
99 return NULL; | |
100 | |
101 ANativeWindow* native_window = | |
102 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | |
103 | |
104 return native_window; | |
105 } | |
106 | |
107 private: | |
108 // The instance of org.chromium.content.app.ChildProcessService. | |
109 base::android::ScopedJavaGlobalRef<jobject> service_; | |
110 | |
111 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureLookupChildImpl); | |
112 }; | |
113 | |
82 // Chrome actually uses the renderer code path for all of its child | 114 // Chrome actually uses the renderer code path for all of its child |
83 // processes such as renderers, plugins, etc. | 115 // processes such as renderers, plugins, etc. |
84 void InternalInitChildProcess(const std::vector<int>& file_ids, | 116 void InternalInitChildProcess(const std::vector<int>& file_ids, |
85 const std::vector<int>& file_fds, | 117 const std::vector<int>& file_fds, |
86 JNIEnv* env, | 118 JNIEnv* env, |
87 jclass clazz, | 119 jclass clazz, |
88 jobject context, | 120 jobject context, |
89 jobject service_in, | 121 jobject service_in, |
90 jint cpu_count, | 122 jint cpu_count, |
91 jlong cpu_features) { | 123 jlong cpu_features) { |
92 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); | 124 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); |
93 | 125 |
94 // Set the CPU properties. | 126 // Set the CPU properties. |
95 android_setCpu(cpu_count, cpu_features); | 127 android_setCpu(cpu_count, cpu_features); |
96 // Register the file descriptors. | 128 // Register the file descriptors. |
97 // This includes the IPC channel, the crash dump signals and resource related | 129 // This includes the IPC channel, the crash dump signals and resource related |
98 // files. | 130 // files. |
99 DCHECK(file_fds.size() == file_ids.size()); | 131 DCHECK(file_fds.size() == file_ids.size()); |
100 for (size_t i = 0; i < file_ids.size(); ++i) | 132 for (size_t i = 0; i < file_ids.size(); ++i) |
101 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 133 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
102 | 134 |
103 content::SurfaceTexturePeer::InitInstance( | 135 content::SurfaceTexturePeer::InitInstance( |
104 new SurfaceTexturePeerChildImpl(service)); | 136 new SurfaceTexturePeerChildImpl(service)); |
105 | 137 |
138 // SurfaceTextureLookup instance must be set before we create a compositor | |
139 // thread that could be using it to initialize resources. | |
140 content::SurfaceTextureLookup::InitInstance( | |
141 new SurfaceTextureLookupChildImpl(service)); | |
142 | |
106 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 143 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
107 } | 144 } |
108 | 145 |
109 } // namespace <anonymous> | 146 } // namespace <anonymous> |
110 | 147 |
111 void InitChildProcess(JNIEnv* env, | 148 void InitChildProcess(JNIEnv* env, |
112 jclass clazz, | 149 jclass clazz, |
113 jobject context, | 150 jobject context, |
114 jobject service, | 151 jobject service, |
115 jintArray j_file_ids, | 152 jintArray j_file_ids, |
(...skipping 18 matching lines...) Expand all Loading... | |
134 | 171 |
135 bool RegisterChildProcessService(JNIEnv* env) { | 172 bool RegisterChildProcessService(JNIEnv* env) { |
136 return RegisterNativesImpl(env); | 173 return RegisterNativesImpl(env); |
137 } | 174 } |
138 | 175 |
139 void ShutdownMainThread(JNIEnv* env, jobject obj) { | 176 void ShutdownMainThread(JNIEnv* env, jobject obj) { |
140 ChildThread::ShutdownThread(); | 177 ChildThread::ShutdownThread(); |
141 } | 178 } |
142 | 179 |
143 } // namespace content | 180 } // namespace content |
OLD | NEW |