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

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

Issue 12390077: Android: Support GPU process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
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/sandboxed_process_service.h" 5 #include "content/app/android/sandboxed_process_service.h"
6 6
7 #include <android/native_window_jni.h>
7 #include <cpu-features.h> 8 #include <cpu-features.h>
8 9
9 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/posix/global_descriptors.h" 12 #include "base/posix/global_descriptors.h"
13 #include "content/common/android/scoped_java_surface.h"
12 #include "content/common/android/surface_texture_peer.h" 14 #include "content/common/android/surface_texture_peer.h"
13 #include "content/common/child_process.h" 15 #include "content/common/child_process.h"
14 #include "content/common/child_thread.h" 16 #include "content/common/child_thread.h"
17 #include "content/common/gpu/gpu_surface_lookup.h"
15 #include "content/public/app/android_library_loader_hooks.h" 18 #include "content/public/app/android_library_loader_hooks.h"
16 #include "content/public/common/content_descriptors.h" 19 #include "content/public/common/content_descriptors.h"
17 #include "ipc/ipc_descriptors.h" 20 #include "ipc/ipc_descriptors.h"
18 #include "jni/SandboxedProcessService_jni.h" 21 #include "jni/SandboxedProcessService_jni.h"
19 22
20 using base::android::AttachCurrentThread; 23 using base::android::AttachCurrentThread;
21 using base::android::CheckException; 24 using base::android::CheckException;
22 using base::android::JavaIntArrayToIntVector; 25 using base::android::JavaIntArrayToIntVector;
23 26
27 namespace content {
28
24 namespace { 29 namespace {
25 30
26 class SurfaceTexturePeerSandboxedImpl : public content::SurfaceTexturePeer { 31 class SurfaceTexturePeerSandboxedImpl : public content::SurfaceTexturePeer,
32 public content::GpuSurfaceLookup {
27 public: 33 public:
28 // |service| is the instance of 34 // |service| is the instance of
29 // org.chromium.content.app.SandboxedProcessService. 35 // org.chromium.content.app.SandboxedProcessService.
30 SurfaceTexturePeerSandboxedImpl(jobject service) 36 SurfaceTexturePeerSandboxedImpl(
bulach 2013/03/05 14:23:58 nit: explicit
no sievers 2013/03/07 00:51:06 Done.
37 const base::android::ScopedJavaLocalRef<jobject>& service)
31 : service_(service) { 38 : service_(service) {
39 GpuSurfaceLookup::InitInstance(this);
32 } 40 }
33 41
34 virtual ~SurfaceTexturePeerSandboxedImpl() { 42 virtual ~SurfaceTexturePeerSandboxedImpl() {
43 GpuSurfaceLookup::InitInstance(NULL);
35 } 44 }
36 45
37 virtual void EstablishSurfaceTexturePeer( 46 virtual void EstablishSurfaceTexturePeer(
38 base::ProcessHandle pid, 47 base::ProcessHandle pid,
39 SurfaceTextureTarget type, 48 SurfaceTextureTarget type,
40 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, 49 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge,
41 int primary_id, 50 int primary_id,
42 int secondary_id) { 51 int secondary_id) {
43 JNIEnv* env = base::android::AttachCurrentThread(); 52 JNIEnv* env = base::android::AttachCurrentThread();
44 content::Java_SandboxedProcessService_establishSurfaceTexturePeer( 53 content::Java_SandboxedProcessService_establishSurfaceTexturePeer(
45 env, service_, pid, type, 54 env, service_.obj(), pid,
46 surface_texture_bridge->j_surface_texture().obj(), primary_id, 55 surface_texture_bridge->j_surface_texture().obj(), primary_id,
47 secondary_id); 56 secondary_id);
48 CheckException(env); 57 CheckException(env);
49 } 58 }
50 59
60 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE {
61 JNIEnv* env = base::android::AttachCurrentThread();
62 ScopedJavaSurface surface(
63 content::Java_SandboxedProcessService_getViewSurface(
64 env, service_.obj(), surface_id));
65 CheckException(env);
bulach 2013/03/05 14:23:58 nit: all generated Java_ methods call "CheckExcept
no sievers 2013/03/07 00:51:06 Done.
66
67 if (surface.j_surface().is_null())
68 return NULL;
69
70 ANativeWindow* native_window = ANativeWindow_fromSurface(
71 env, surface.j_surface().obj());
72
73 return native_window;
74 }
75
51 private: 76 private:
52 // The instance of org.chromium.content.app.SandboxedProcessService. 77 // The instance of org.chromium.content.app.SandboxedProcessService.
53 jobject service_; 78 base::android::ScopedJavaGlobalRef<jobject> service_;
54 79
55 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl); 80 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl);
56 }; 81 };
57 82
58 // Chrome actually uses the renderer code path for all of its sandboxed 83 // Chrome actually uses the renderer code path for all of its sandboxed
59 // processes such as renderers, plugins, etc. 84 // processes such as renderers, plugins, etc.
60 void InternalInitSandboxedProcess(const std::vector<int>& file_ids, 85 void InternalInitSandboxedProcess(const std::vector<int>& file_ids,
61 const std::vector<int>& file_fds, 86 const std::vector<int>& file_fds,
62 JNIEnv* env, 87 JNIEnv* env,
63 jclass clazz, 88 jclass clazz,
64 jobject context, 89 jobject context,
65 jobject service, 90 jobject service_in,
66 jint cpu_count, 91 jint cpu_count,
67 jlong cpu_features) { 92 jlong cpu_features) {
93 base::android::ScopedJavaLocalRef<jobject> service(env, service_in);
94
68 // Set the CPU properties. 95 // Set the CPU properties.
69 android_setCpu(cpu_count, cpu_features); 96 android_setCpu(cpu_count, cpu_features);
70 // Register the file descriptors. 97 // Register the file descriptors.
71 // This includes the IPC channel, the crash dump signals and resource related 98 // This includes the IPC channel, the crash dump signals and resource related
72 // files. 99 // files.
73 DCHECK(file_fds.size() == file_ids.size()); 100 DCHECK(file_fds.size() == file_ids.size());
74 for (size_t i = 0; i < file_ids.size(); ++i) 101 for (size_t i = 0; i < file_ids.size(); ++i)
75 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); 102 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]);
76 103
77 content::SurfaceTexturePeer::InitInstance( 104 content::SurfaceTexturePeer::InitInstance(
78 new SurfaceTexturePeerSandboxedImpl(service)); 105 new SurfaceTexturePeerSandboxedImpl(service));
79 106
80 } 107 }
81 108
82 void QuitSandboxMainThreadMessageLoop() { 109 void QuitSandboxMainThreadMessageLoop() {
83 MessageLoop::current()->Quit(); 110 MessageLoop::current()->Quit();
84 } 111 }
85 112
86 } // namespace <anonymous> 113 } // namespace <anonymous>
87 114
88 namespace content {
89
90 void InitSandboxedProcess(JNIEnv* env, 115 void InitSandboxedProcess(JNIEnv* env,
91 jclass clazz, 116 jclass clazz,
92 jobject context, 117 jobject context,
93 jobject service, 118 jobject service,
94 jintArray j_file_ids, 119 jintArray j_file_ids,
95 jintArray j_file_fds, 120 jintArray j_file_fds,
96 jint cpu_count, 121 jint cpu_count,
97 jlong cpu_features) { 122 jlong cpu_features) {
98 std::vector<int> file_ids; 123 std::vector<int> file_ids;
99 std::vector<int> file_fds; 124 std::vector<int> file_fds;
(...skipping 19 matching lines...) Expand all
119 ChildProcess* current_process = ChildProcess::current(); 144 ChildProcess* current_process = ChildProcess::current();
120 if (!current_process) 145 if (!current_process)
121 return; 146 return;
122 ChildThread* main_child_thread = current_process->main_thread(); 147 ChildThread* main_child_thread = current_process->main_thread();
123 if (main_child_thread && main_child_thread->message_loop()) 148 if (main_child_thread && main_child_thread->message_loop())
124 main_child_thread->message_loop()->PostTask(FROM_HERE, 149 main_child_thread->message_loop()->PostTask(FROM_HERE,
125 base::Bind(&QuitSandboxMainThreadMessageLoop)); 150 base::Bind(&QuitSandboxMainThreadMessageLoop));
126 } 151 }
127 152
128 } // namespace content 153 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698