Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/android/surface_texture_peer_browser_impl.h" | |
| 6 | |
| 7 #include "content/browser/android/media_player_manager_android.h" | |
| 8 #include "content/browser/renderer_host/render_view_host_impl.h" | |
| 9 #include "content/common/android/surface_callback.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/browser/render_process_host.h" | |
| 12 #include "media/base/android/media_player_bridge.h" | |
| 13 | |
| 14 #include "jni/BrowserProcessSurfaceTexture_jni.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 void SetSurfacePeer(jobject j_surface, | |
| 19 base::ProcessHandle pid, | |
| 20 int primary_id, | |
| 21 int secondary_id) { | |
| 22 int renderer_id = 0; | |
| 23 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | |
| 24 while (!it.IsAtEnd()) { | |
| 25 if (it.GetCurrentValue()->GetHandle() == pid) { | |
| 26 renderer_id = it.GetCurrentValue()->GetID(); | |
| 27 break; | |
| 28 } | |
| 29 it.Advance(); | |
| 30 } | |
| 31 | |
| 32 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 33 DCHECK(env); | |
| 34 if (renderer_id) { | |
| 35 RenderViewHostImpl* host = RenderViewHostImpl::FromID( | |
| 36 renderer_id, primary_id); | |
| 37 if (host) { | |
| 38 media::MediaPlayerBridge* player = | |
| 39 host->media_player_manager()->GetPlayer(secondary_id); | |
| 40 if (player) { | |
| 41 player->SetVideoSurface(j_surface); | |
| 42 } | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 ReleaseSurface(j_surface); | |
| 47 env->DeleteGlobalRef(j_surface); | |
| 48 } | |
| 49 | |
| 50 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl( | |
| 51 bool player_in_render_process) | |
| 52 : player_in_render_process_(player_in_render_process) { | |
| 53 } | |
| 54 | |
| 55 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() { | |
| 56 if (surface_.obj()) | |
| 57 ReleaseSurface(surface_.obj()); | |
| 58 } | |
| 59 | |
| 60 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer( | |
| 61 base::ProcessHandle pid, | |
| 62 SurfaceTextureTarget type, | |
| 63 jobject j_surface_texture, | |
| 64 int primary_id, | |
| 65 int secondary_id) { | |
| 66 if (j_surface_texture == NULL) | |
| 67 return; | |
| 68 | |
| 69 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 70 DCHECK(env); | |
| 71 if (player_in_render_process_) { | |
| 72 Java_BrowserProcessSurfaceTexture_establishSurfaceTexturePeer( | |
| 73 env, pid, type, j_surface_texture, primary_id, secondary_id); | |
| 74 } else { | |
| 75 base::android::ScopedJavaLocalRef<jclass> cls( | |
| 76 base::android::GetClass(env, "android/view/Surface")); | |
| 77 jmethodID constructor = GetMethodID(env, cls, "<init>", | |
| 78 "(Landroid/graphics/SurfaceTexture;)V"); | |
| 79 ScopedJavaLocalRef<jobject> tmp(env, | |
| 80 env->NewObject(cls.obj(), constructor, j_surface_texture)); | |
| 81 jobject surface = env->NewGlobalRef(tmp.obj()); | |
|
Yaron
2012/09/05 07:03:56
Use ScopedJavaGlobalRef?
qinmin
2012/09/05 19:34:42
This is problematic as we cannot pass a ScopedJava
| |
| 82 | |
| 83 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 84 base::Bind(&SetSurfacePeer, surface, | |
| 85 pid, primary_id, secondary_id)); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 bool RegisterBrowserProcessSurfaceTexture(JNIEnv* env) { | |
| 90 return RegisterNativesImpl(env); | |
| 91 } | |
| 92 | |
| 93 } // namespace content | |
| OLD | NEW |