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

Side by Side Diff: content/browser/android/sandboxed_process_launcher.cc

Issue 12390077: Android: Support GPU process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments and rebase 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/browser/android/sandboxed_process_launcher.h" 5 #include "content/browser/android/sandboxed_process_launcher.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "content/browser/android/media_player_manager_android.h"
12 #include "content/browser/renderer_host/compositor_impl_android.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/common/android/scoped_java_surface.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/render_process_host.h"
11 #include "jni/SandboxedProcessLauncher_jni.h" 17 #include "jni/SandboxedProcessLauncher_jni.h"
18 #include "media/base/android/media_player_bridge.h"
12 19
13 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
14 using base::android::ToJavaArrayOfStrings; 21 using base::android::ToJavaArrayOfStrings;
22 using base::android::ScopedJavaGlobalRef;
15 using base::android::ScopedJavaLocalRef; 23 using base::android::ScopedJavaLocalRef;
16 using content::StartSandboxedProcessCallback; 24 using content::StartSandboxedProcessCallback;
17 25
18 namespace content { 26 namespace content {
19 27
28 namespace {
29
30 // Pass a java surface object to the MediaPlayerBridge object
31 // identified by render process handle, render view ID and player ID.
32 static void SetSurfacePeer(
33 const base::android::JavaRef<jobject>& surface,
34 base::ProcessHandle render_process_handle,
35 int render_view_id,
36 int player_id) {
37 int renderer_id = 0;
38 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
39 while (!it.IsAtEnd()) {
40 if (it.GetCurrentValue()->GetHandle() == render_process_handle) {
41 renderer_id = it.GetCurrentValue()->GetID();
42 break;
43 }
44 it.Advance();
45 }
46
47 if (renderer_id) {
48 RenderViewHostImpl* host = RenderViewHostImpl::FromID(
49 renderer_id, render_view_id);
50 if (host) {
51 media::MediaPlayerBridge* player =
52 host->media_player_manager()->GetPlayer(player_id);
53 if (player &&
54 player != host->media_player_manager()->GetFullscreenPlayer()) {
55 ScopedJavaSurface scoped_surface(surface);
56 player->SetVideoSurface(scoped_surface.j_surface().obj());
57 }
58 }
59 }
60 }
61
62 } // anonymous namespace
63
20 // Called from SandboxedProcessLauncher.java when the SandboxedProcess was 64 // Called from SandboxedProcessLauncher.java when the SandboxedProcess was
21 // started. 65 // started.
22 // |client_context| is the pointer to StartSandboxedProcessCallback which was 66 // |client_context| is the pointer to StartSandboxedProcessCallback which was
23 // passed in from StartSandboxedProcess. 67 // passed in from StartSandboxedProcess.
24 // |handle| is the processID of the child process as originated in Java, 0 if 68 // |handle| is the processID of the child process as originated in Java, 0 if
25 // the SandboxedProcess could not be created. 69 // the SandboxedProcess could not be created.
26 static void OnSandboxedProcessStarted(JNIEnv*, 70 static void OnSandboxedProcessStarted(JNIEnv*,
27 jclass, 71 jclass,
28 jint client_context, 72 jint client_context,
29 jint handle) { 73 jint handle) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 j_file_auto_close.obj(), 123 j_file_auto_close.obj(),
80 reinterpret_cast<jint>(new StartSandboxedProcessCallback(callback))); 124 reinterpret_cast<jint>(new StartSandboxedProcessCallback(callback)));
81 } 125 }
82 126
83 void StopSandboxedProcess(base::ProcessHandle handle) { 127 void StopSandboxedProcess(base::ProcessHandle handle) {
84 JNIEnv* env = AttachCurrentThread(); 128 JNIEnv* env = AttachCurrentThread();
85 DCHECK(env); 129 DCHECK(env);
86 Java_SandboxedProcessLauncher_stop(env, static_cast<jint>(handle)); 130 Java_SandboxedProcessLauncher_stop(env, static_cast<jint>(handle));
87 } 131 }
88 132
133 void EstablishSurfacePeer(
134 JNIEnv* env, jclass clazz,
135 jint pid, jobject surface, jint primary_id, jint secondary_id) {
136 ScopedJavaGlobalRef<jobject> jsurface;
137 jsurface.Reset(env, surface);
138 if (jsurface.is_null())
139 return;
140
141 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
142 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
143 &SetSurfacePeer, jsurface, pid, primary_id, secondary_id));
144 }
145
146 jobject GetViewSurface(JNIEnv* env, jclass clazz, jint surface_id) {
147 // This is a synchronous call from the GPU process and is expected to be
148 // handled on a binder thread. Handling this on the UI thread will lead
149 // to deadlocks.
150 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
151 return CompositorImpl::GetSurface(surface_id);
152 }
153
89 bool RegisterSandboxedProcessLauncher(JNIEnv* env) { 154 bool RegisterSandboxedProcessLauncher(JNIEnv* env) {
90 return RegisterNativesImpl(env); 155 return RegisterNativesImpl(env);
91 } 156 }
92 157
93 } // namespace content 158 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/content_view_render_view.cc ('k') | content/browser/renderer_host/compositor_impl_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698