Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: content/app/android/child_process_service.cc

Issue 634643002: content: Out-of-process GPU service support for SurfaceTexture backed GpuMemoryBuffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and address some review feedback Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 class SurfaceTextureManagerImpl : public SurfaceTextureManager,
34 public GpuSurfaceLookup, 34 public SurfaceTexturePeer,
35 public SurfaceTextureLookup { 35 public GpuSurfaceLookup {
36 public: 36 public:
37 // |service| is the instance of 37 // |service| is the instance of
38 // org.chromium.content.app.ChildProcessService. 38 // org.chromium.content.app.ChildProcessService.
39 explicit SurfaceTexturePeerChildImpl( 39 explicit SurfaceTextureManagerImpl(
40 const base::android::ScopedJavaLocalRef<jobject>& service) 40 const base::android::ScopedJavaLocalRef<jobject>& service)
41 : service_(service) { 41 : service_(service) {
42 SurfaceTexturePeer::InitInstance(this);
42 GpuSurfaceLookup::InitInstance(this); 43 GpuSurfaceLookup::InitInstance(this);
43 SurfaceTextureLookup::InitInstance(this); 44 }
no sievers 2014/10/07 22:12:45 One thing I don't like so much is that this class
reveman 2014/10/08 15:56:39 Done.
45 virtual ~SurfaceTextureManagerImpl() {
46 SurfaceTexturePeer::InitInstance(NULL);
47 GpuSurfaceLookup::InitInstance(NULL);
no sievers 2014/10/07 22:12:45 Should it also do SurfaceTextureManager::InitInsta
reveman 2014/10/08 15:56:39 That's the responsibility of InternalInitChildProc
44 } 48 }
45 49
46 virtual ~SurfaceTexturePeerChildImpl() { 50 // Overridden from SurfaceTextureManager:
47 GpuSurfaceLookup::InitInstance(NULL); 51 virtual void RegisterSurfaceTexture(
48 SurfaceTextureLookup::InitInstance(NULL); 52 int surface_texture_id,
53 int client_id,
54 gfx::SurfaceTexture* surface_texture) OVERRIDE {
55 JNIEnv* env = base::android::AttachCurrentThread();
56 gfx::ScopedJavaSurface surface(surface_texture);
57 Java_ChildProcessService_registerSurfaceTextureSurface(
58 env,
59 service_.obj(),
60 surface_texture_id,
61 client_id,
62 surface.j_surface().obj());
63 DCHECK(!base::android::HasException(env));
49 } 64 }
50 65 virtual void UnregisterSurfaceTexture(int surface_texture_id,
51 // Overridden from SurfaceTexturePeer: 66 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(); 67 JNIEnv* env = base::android::AttachCurrentThread();
58 content::Java_ChildProcessService_establishSurfaceTexturePeer( 68 Java_ChildProcessService_unregisterSurfaceTextureSurface(
59 env, service_.obj(), pid, 69 env, service_.obj(), surface_texture_id, client_id);
60 surface_texture->j_surface_texture().obj(), primary_id, 70 DCHECK(!base::android::HasException(env));
61 secondary_id);
62 CheckException(env);
63 } 71 }
64 72 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_texture_id,
65 // Overridden from GpuSurfaceLookup: 73 int client_id) OVERRIDE {
66 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE {
67 JNIEnv* env = base::android::AttachCurrentThread(); 74 JNIEnv* env = base::android::AttachCurrentThread();
68 gfx::ScopedJavaSurface surface( 75 gfx::ScopedJavaSurface surface(
69 content::Java_ChildProcessService_getViewSurface( 76 Java_ChildProcessService_getSurfaceTextureSurface(
70 env, service_.obj(), surface_id)); 77 env, service_.obj(), surface_texture_id, client_id));
78 DCHECK(!base::android::HasException(env));
71 79
72 if (surface.j_surface().is_null()) 80 if (surface.j_surface().is_null())
73 return NULL; 81 return NULL;
74 82
75 // Note: This ensures that any local references used by 83 // Note: This ensures that any local references used by
76 // ANativeWindow_fromSurface are released immediately. This is needed as a 84 // ANativeWindow_fromSurface are released immediately. This is needed as a
77 // workaround for https://code.google.com/p/android/issues/detail?id=68174 85 // workaround for https://code.google.com/p/android/issues/detail?id=68174
78 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); 86 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
79 ANativeWindow* native_window = 87 ANativeWindow* native_window =
80 ANativeWindow_fromSurface(env, surface.j_surface().obj()); 88 ANativeWindow_fromSurface(env, surface.j_surface().obj());
81 89
82 return native_window; 90 return native_window;
83 } 91 }
84 92
85 // Overridden from SurfaceTextureLookup: 93 // Overridden from SurfaceTexturePeer:
86 virtual gfx::AcceleratedWidget AcquireNativeWidget(int primary_id, 94 virtual void EstablishSurfaceTexturePeer(
87 int secondary_id) 95 base::ProcessHandle pid,
88 OVERRIDE { 96 scoped_refptr<gfx::SurfaceTexture> surface_texture,
97 int primary_id,
98 int secondary_id) OVERRIDE {
99 JNIEnv* env = base::android::AttachCurrentThread();
100 content::Java_ChildProcessService_establishSurfaceTexturePeer(
101 env,
102 service_.obj(),
103 pid,
104 surface_texture->j_surface_texture().obj(),
105 primary_id,
106 secondary_id);
107 DCHECK(!base::android::HasException(env));
108 }
109
110 // Overridden from GpuSurfaceLookup:
111 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE {
89 JNIEnv* env = base::android::AttachCurrentThread(); 112 JNIEnv* env = base::android::AttachCurrentThread();
90 gfx::ScopedJavaSurface surface( 113 gfx::ScopedJavaSurface surface(
91 content::Java_ChildProcessService_getSurfaceTextureSurface( 114 content::Java_ChildProcessService_getViewSurface(
92 env, service_.obj(), primary_id, secondary_id)); 115 env, service_.obj(), surface_id));
116 DCHECK(!base::android::HasException(env));
93 117
94 if (surface.j_surface().is_null()) 118 if (surface.j_surface().is_null())
95 return NULL; 119 return NULL;
96 120
97 // Note: This ensures that any local references used by 121 // Note: This ensures that any local references used by
98 // ANativeWindow_fromSurface are released immediately. This is needed as a 122 // ANativeWindow_fromSurface are released immediately. This is needed as a
99 // workaround for https://code.google.com/p/android/issues/detail?id=68174 123 // workaround for https://code.google.com/p/android/issues/detail?id=68174
100 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); 124 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
101 ANativeWindow* native_window = 125 ANativeWindow* native_window =
102 ANativeWindow_fromSurface(env, surface.j_surface().obj()); 126 ANativeWindow_fromSurface(env, surface.j_surface().obj());
103 127
104 return native_window; 128 return native_window;
105 } 129 }
106 130
107 private: 131 private:
108 // The instance of org.chromium.content.app.ChildProcessService. 132 // The instance of org.chromium.content.app.ChildProcessService.
109 base::android::ScopedJavaGlobalRef<jobject> service_; 133 base::android::ScopedJavaGlobalRef<jobject> service_;
110 134
111 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); 135 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl);
112 }; 136 };
113 137
114 // Chrome actually uses the renderer code path for all of its child 138 // Chrome actually uses the renderer code path for all of its child
115 // processes such as renderers, plugins, etc. 139 // processes such as renderers, plugins, etc.
116 void InternalInitChildProcess(const std::vector<int>& file_ids, 140 void InternalInitChildProcess(const std::vector<int>& file_ids,
117 const std::vector<int>& file_fds, 141 const std::vector<int>& file_fds,
118 JNIEnv* env, 142 JNIEnv* env,
119 jclass clazz, 143 jclass clazz,
120 jobject context, 144 jobject context,
121 jobject service_in, 145 jobject service_in,
122 jint cpu_count, 146 jint cpu_count,
123 jlong cpu_features) { 147 jlong cpu_features) {
124 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); 148 base::android::ScopedJavaLocalRef<jobject> service(env, service_in);
125 149
126 // Set the CPU properties. 150 // Set the CPU properties.
127 android_setCpu(cpu_count, cpu_features); 151 android_setCpu(cpu_count, cpu_features);
128 // Register the file descriptors. 152 // Register the file descriptors.
129 // This includes the IPC channel, the crash dump signals and resource related 153 // This includes the IPC channel, the crash dump signals and resource related
130 // files. 154 // files.
131 DCHECK(file_fds.size() == file_ids.size()); 155 DCHECK(file_fds.size() == file_ids.size());
132 for (size_t i = 0; i < file_ids.size(); ++i) 156 for (size_t i = 0; i < file_ids.size(); ++i)
133 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); 157 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]);
134 158
135 // SurfaceTexturePeerChildImpl implements the SurfaceTextureLookup interface, 159 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 160
141 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); 161 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env);
142 } 162 }
143 163
144 } // namespace <anonymous> 164 } // namespace <anonymous>
145 165
146 void InitChildProcess(JNIEnv* env, 166 void InitChildProcess(JNIEnv* env,
147 jclass clazz, 167 jclass clazz,
148 jobject context, 168 jobject context,
149 jobject service, 169 jobject service,
(...skipping 19 matching lines...) Expand all
169 189
170 bool RegisterChildProcessService(JNIEnv* env) { 190 bool RegisterChildProcessService(JNIEnv* env) {
171 return RegisterNativesImpl(env); 191 return RegisterNativesImpl(env);
172 } 192 }
173 193
174 void ShutdownMainThread(JNIEnv* env, jobject obj) { 194 void ShutdownMainThread(JNIEnv* env, jobject obj) {
175 ChildThread::ShutdownThread(); 195 ChildThread::ShutdownThread();
176 } 196 }
177 197
178 } // namespace content 198 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698