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

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

Powered by Google App Engine
This is Rietveld 408576698