| OLD | NEW |
| 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/surface_texture_peer_browser_impl.h" | 5 #include "content/browser/android/surface_texture_peer_browser_impl.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" |
| 7 #include "content/browser/android/media_player_manager_android.h" | 8 #include "content/browser/android/media_player_manager_android.h" |
| 8 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 9 #include "content/common/android/surface_callback.h" | 10 #include "content/common/android/scoped_java_surface.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
| 12 #include "jni/BrowserProcessSurfaceTexture_jni.h" | |
| 13 #include "media/base/android/media_player_bridge.h" | 13 #include "media/base/android/media_player_bridge.h" |
| 14 | 14 |
| 15 using base::android::MethodID; | 15 using base::android::MethodID; |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 // Pass a java surface object to the MediaPlayerBridge object | 19 // Pass a java surface object to the MediaPlayerBridge object |
| 20 // identified by render process handle, render view ID and player ID. | 20 // identified by render process handle, render view ID and player ID. |
| 21 static void SetSurfacePeer( | 21 static void SetSurfacePeer( |
| 22 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, | 22 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 36 JNIEnv* env = base::android::AttachCurrentThread(); | 36 JNIEnv* env = base::android::AttachCurrentThread(); |
| 37 DCHECK(env); | 37 DCHECK(env); |
| 38 if (renderer_id) { | 38 if (renderer_id) { |
| 39 RenderViewHostImpl* host = RenderViewHostImpl::FromID( | 39 RenderViewHostImpl* host = RenderViewHostImpl::FromID( |
| 40 renderer_id, render_view_id); | 40 renderer_id, render_view_id); |
| 41 if (host) { | 41 if (host) { |
| 42 media::MediaPlayerBridge* player = | 42 media::MediaPlayerBridge* player = |
| 43 host->media_player_manager()->GetPlayer(player_id); | 43 host->media_player_manager()->GetPlayer(player_id); |
| 44 if (player && | 44 if (player && |
| 45 player != host->media_player_manager()->GetFullscreenPlayer()) { | 45 player != host->media_player_manager()->GetFullscreenPlayer()) { |
| 46 base::android::ScopedJavaLocalRef<jclass> cls( | 46 ScopedJavaSurface surface(surface_texture_bridge.get()); |
| 47 base::android::GetClass(env, "android/view/Surface")); | 47 player->SetVideoSurface(surface.j_surface().obj()); |
| 48 jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( | |
| 49 env, cls.obj(), "<init>", "(Landroid/graphics/SurfaceTexture;)V"); | |
| 50 ScopedJavaLocalRef<jobject> j_surface( | |
| 51 env, env->NewObject( | |
| 52 cls.obj(), constructor, | |
| 53 surface_texture_bridge->j_surface_texture().obj())); | |
| 54 player->SetVideoSurface(j_surface.obj()); | |
| 55 ReleaseSurface(j_surface.obj()); | |
| 56 } | 48 } |
| 57 } | 49 } |
| 58 } | 50 } |
| 59 } | 51 } |
| 60 | 52 |
| 61 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl( | 53 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl() { |
| 62 bool player_in_render_process) | |
| 63 : player_in_render_process_(player_in_render_process) { | |
| 64 } | 54 } |
| 65 | 55 |
| 66 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() { | 56 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() { |
| 67 if (surface_.obj()) | |
| 68 ReleaseSurface(surface_.obj()); | |
| 69 } | 57 } |
| 70 | 58 |
| 71 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer( | 59 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer( |
| 72 base::ProcessHandle render_process_handle, | 60 base::ProcessHandle render_process_handle, |
| 73 SurfaceTextureTarget type, | |
| 74 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, | 61 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, |
| 75 int render_view_id, | 62 int render_view_id, |
| 76 int player_id) { | 63 int player_id) { |
| 77 if (!surface_texture_bridge) | 64 if (!surface_texture_bridge) |
| 78 return; | 65 return; |
| 79 | 66 |
| 80 JNIEnv* env = base::android::AttachCurrentThread(); | 67 JNIEnv* env = base::android::AttachCurrentThread(); |
| 81 DCHECK(env); | 68 DCHECK(env); |
| 82 if (player_in_render_process_) { | 69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 83 Java_BrowserProcessSurfaceTexture_establishSurfaceTexturePeer( | 70 &SetSurfacePeer, surface_texture_bridge, render_process_handle, |
| 84 env, render_process_handle, type, | 71 render_view_id, player_id)); |
| 85 surface_texture_bridge->j_surface_texture().obj(), | |
| 86 render_view_id, player_id); | |
| 87 } else { | |
| 88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | |
| 89 &SetSurfacePeer, surface_texture_bridge, render_process_handle, | |
| 90 render_view_id, player_id)); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 bool SurfaceTexturePeerBrowserImpl::RegisterBrowserProcessSurfaceTexture( | |
| 95 JNIEnv* env) { | |
| 96 return RegisterNativesImpl(env); | |
| 97 } | 72 } |
| 98 | 73 |
| 99 } // namespace content | 74 } // namespace content |
| OLD | NEW |