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

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: 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 {
reveman 2014/10/06 19:05:15 I decided to consolidate these into one implementa
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 }
45 virtual ~SurfaceTextureManagerImpl() {
46 SurfaceTexturePeer::InitInstance(NULL);
47 GpuSurfaceLookup::InitInstance(NULL);
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 Java_ChildProcessService_registerSurfaceTexture(
57 env,
58 service_.obj(),
59 surface_texture_id,
60 client_id,
61 surface_texture->j_surface_texture().obj());
62 DCHECK(!base::android::HasException(env));
49 } 63 }
50 64 virtual void UnregisterSurfaceTexture(int surface_texture_id,
51 // Overridden from SurfaceTexturePeer: 65 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(); 66 JNIEnv* env = base::android::AttachCurrentThread();
58 content::Java_ChildProcessService_establishSurfaceTexturePeer( 67 Java_ChildProcessService_unregisterSurfaceTexture(
59 env, service_.obj(), pid, 68 env, service_.obj(), surface_texture_id, client_id);
60 surface_texture->j_surface_texture().obj(), primary_id, 69 DCHECK(!base::android::HasException(env));
61 secondary_id);
62 CheckException(env);
63 } 70 }
64 71 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_texture_id,
65 // Overridden from GpuSurfaceLookup: 72 int client_id) OVERRIDE {
66 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE {
67 JNIEnv* env = base::android::AttachCurrentThread(); 73 JNIEnv* env = base::android::AttachCurrentThread();
68 gfx::ScopedJavaSurface surface( 74 gfx::ScopedJavaSurface surface(
69 content::Java_ChildProcessService_getViewSurface( 75 Java_ChildProcessService_getSurfaceTextureSurface(
70 env, service_.obj(), surface_id)); 76 env, service_.obj(), surface_texture_id, client_id));
77 DCHECK(!base::android::HasException(env));
71 78
72 if (surface.j_surface().is_null()) 79 if (surface.j_surface().is_null())
73 return NULL; 80 return NULL;
74 81
75 // Note: This ensures that any local references used by 82 // Note: This ensures that any local references used by
76 // ANativeWindow_fromSurface are released immediately. This is needed as a 83 // ANativeWindow_fromSurface are released immediately. This is needed as a
77 // workaround for https://code.google.com/p/android/issues/detail?id=68174 84 // workaround for https://code.google.com/p/android/issues/detail?id=68174
78 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); 85 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
79 ANativeWindow* native_window = 86 ANativeWindow* native_window =
80 ANativeWindow_fromSurface(env, surface.j_surface().obj()); 87 ANativeWindow_fromSurface(env, surface.j_surface().obj());
81 88
82 return native_window; 89 return native_window;
83 } 90 }
84 91
85 // Overridden from SurfaceTextureLookup: 92 // Overridden from SurfaceTexturePeer:
86 virtual gfx::AcceleratedWidget AcquireNativeWidget(int primary_id, 93 virtual void EstablishSurfaceTexturePeer(
87 int secondary_id) 94 base::ProcessHandle pid,
88 OVERRIDE { 95 scoped_refptr<gfx::SurfaceTexture> surface_texture,
96 int primary_id,
97 int secondary_id) OVERRIDE {
98 JNIEnv* env = base::android::AttachCurrentThread();
99 content::Java_ChildProcessService_establishSurfaceTexturePeer(
100 env,
101 service_.obj(),
102 pid,
103 surface_texture->j_surface_texture().obj(),
104 primary_id,
105 secondary_id);
106 DCHECK(!base::android::HasException(env));
107 }
108
109 // Overridden from GpuSurfaceLookup:
110 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE {
89 JNIEnv* env = base::android::AttachCurrentThread(); 111 JNIEnv* env = base::android::AttachCurrentThread();
90 gfx::ScopedJavaSurface surface( 112 gfx::ScopedJavaSurface surface(
91 content::Java_ChildProcessService_getSurfaceTextureSurface( 113 content::Java_ChildProcessService_getViewSurface(
92 env, service_.obj(), primary_id, secondary_id)); 114 env, service_.obj(), surface_id));
115 DCHECK(!base::android::HasException(env));
93 116
94 if (surface.j_surface().is_null()) 117 if (surface.j_surface().is_null())
95 return NULL; 118 return NULL;
96 119
97 // Note: This ensures that any local references used by 120 // Note: This ensures that any local references used by
98 // ANativeWindow_fromSurface are released immediately. This is needed as a 121 // ANativeWindow_fromSurface are released immediately. This is needed as a
99 // workaround for https://code.google.com/p/android/issues/detail?id=68174 122 // workaround for https://code.google.com/p/android/issues/detail?id=68174
100 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); 123 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
101 ANativeWindow* native_window = 124 ANativeWindow* native_window =
102 ANativeWindow_fromSurface(env, surface.j_surface().obj()); 125 ANativeWindow_fromSurface(env, surface.j_surface().obj());
103 126
104 return native_window; 127 return native_window;
105 } 128 }
106 129
107 private: 130 private:
108 // The instance of org.chromium.content.app.ChildProcessService. 131 // The instance of org.chromium.content.app.ChildProcessService.
109 base::android::ScopedJavaGlobalRef<jobject> service_; 132 base::android::ScopedJavaGlobalRef<jobject> service_;
110 133
111 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerChildImpl); 134 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl);
112 }; 135 };
113 136
114 // Chrome actually uses the renderer code path for all of its child 137 // Chrome actually uses the renderer code path for all of its child
115 // processes such as renderers, plugins, etc. 138 // processes such as renderers, plugins, etc.
116 void InternalInitChildProcess(const std::vector<int>& file_ids, 139 void InternalInitChildProcess(const std::vector<int>& file_ids,
117 const std::vector<int>& file_fds, 140 const std::vector<int>& file_fds,
118 JNIEnv* env, 141 JNIEnv* env,
119 jclass clazz, 142 jclass clazz,
120 jobject context, 143 jobject context,
121 jobject service_in, 144 jobject service_in,
122 jint cpu_count, 145 jint cpu_count,
123 jlong cpu_features) { 146 jlong cpu_features) {
124 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); 147 base::android::ScopedJavaLocalRef<jobject> service(env, service_in);
125 148
126 // Set the CPU properties. 149 // Set the CPU properties.
127 android_setCpu(cpu_count, cpu_features); 150 android_setCpu(cpu_count, cpu_features);
128 // Register the file descriptors. 151 // Register the file descriptors.
129 // This includes the IPC channel, the crash dump signals and resource related 152 // This includes the IPC channel, the crash dump signals and resource related
130 // files. 153 // files.
131 DCHECK(file_fds.size() == file_ids.size()); 154 DCHECK(file_fds.size() == file_ids.size());
132 for (size_t i = 0; i < file_ids.size(); ++i) 155 for (size_t i = 0; i < file_ids.size(); ++i)
133 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); 156 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]);
134 157
135 // SurfaceTexturePeerChildImpl implements the SurfaceTextureLookup interface, 158 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 159
141 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); 160 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env);
142 } 161 }
143 162
144 } // namespace <anonymous> 163 } // namespace <anonymous>
145 164
146 void InitChildProcess(JNIEnv* env, 165 void InitChildProcess(JNIEnv* env,
147 jclass clazz, 166 jclass clazz,
148 jobject context, 167 jobject context,
149 jobject service, 168 jobject service,
(...skipping 19 matching lines...) Expand all
169 188
170 bool RegisterChildProcessService(JNIEnv* env) { 189 bool RegisterChildProcessService(JNIEnv* env) {
171 return RegisterNativesImpl(env); 190 return RegisterNativesImpl(env);
172 } 191 }
173 192
174 void ShutdownMainThread(JNIEnv* env, jobject obj) { 193 void ShutdownMainThread(JNIEnv* env, jobject obj) {
175 ChildThread::ShutdownThread(); 194 ChildThread::ShutdownThread();
176 } 195 }
177 196
178 } // namespace content 197 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698