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.
5 #include "content/browser/android/surface_texture_peer_browser_impl.h"
7 #include "content/browser/media/android/browser_media_player_manager.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "media/base/android/media_player_android.h"
12 #include "ui/gl/android/scoped_java_surface.h"
18 // Pass a java surface object to the MediaPlayerAndroid object
19 // identified by render process handle, render view ID and player ID.
20 static void SetSurfacePeer(
21 scoped_refptr
<gfx::SurfaceTexture
> surface_texture
,
22 base::ProcessHandle render_process_handle
,
26 RenderProcessHost::iterator it
= RenderProcessHost::AllHostsIterator();
27 while (!it
.IsAtEnd()) {
28 if (it
.GetCurrentValue()->GetHandle() == render_process_handle
) {
29 renderer_id
= it
.GetCurrentValue()->GetID();
36 RenderViewHostImpl
* host
= RenderViewHostImpl::FromID(
37 renderer_id
, render_view_id
);
39 media::MediaPlayerAndroid
* player
=
40 host
->media_player_manager()->GetPlayer(player_id
);
42 player
!= host
->media_player_manager()->GetFullscreenPlayer()) {
43 gfx::ScopedJavaSurface
surface(surface_texture
.get());
44 player
->SetVideoSurface(surface
.Pass());
50 } // anonymous namespace
52 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl() {
55 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() {
58 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer(
59 base::ProcessHandle render_process_handle
,
60 scoped_refptr
<gfx::SurfaceTexture
> surface_texture
,
63 if (!surface_texture
.get())
66 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
, base::Bind(
67 &SetSurfacePeer
, surface_texture
, render_process_handle
,
68 render_view_id
, player_id
));
71 } // namespace content