Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / android / surface_texture_peer_browser_impl.cc
blob4f61887f880db73b7212700daf29eda77382504e
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/frame_host/render_frame_host_impl.h"
8 #include "content/browser/media/android/browser_media_player_manager.h"
9 #include "content/browser/media/media_web_contents_observer.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "media/base/android/media_player_android.h"
14 #include "ui/gl/android/scoped_java_surface.h"
16 namespace content {
18 namespace {
20 // Pass a java surface object to the MediaPlayerAndroid object
21 // identified by render process handle, render frame ID and player ID.
22 static void SetSurfacePeer(
23 scoped_refptr<gfx::SurfaceTexture> surface_texture,
24 base::ProcessHandle render_process_handle,
25 int render_frame_id,
26 int player_id) {
27 int render_process_id = 0;
28 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
29 while (!it.IsAtEnd()) {
30 if (it.GetCurrentValue()->GetHandle() == render_process_handle) {
31 render_process_id = it.GetCurrentValue()->GetID();
32 break;
34 it.Advance();
36 if (!render_process_id) {
37 DVLOG(1) << "Cannot find render process for render_process_handle "
38 << render_process_handle;
39 return;
42 RenderFrameHostImpl* frame =
43 RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
44 if (!frame) {
45 DVLOG(1) << "Cannot find frame for render_frame_id " << render_frame_id;
46 return;
49 RenderViewHostImpl* view =
50 static_cast<RenderViewHostImpl*>(frame->GetRenderViewHost());
51 BrowserMediaPlayerManager* player_manager =
52 view->media_web_contents_observer()->GetMediaPlayerManager(frame);
53 if (!player_manager) {
54 DVLOG(1) << "Cannot find the media player manager for frame " << frame;
55 return;
58 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id);
59 if (!player) {
60 DVLOG(1) << "Cannot find media player for player_id " << player_id;
61 return;
64 if (player != player_manager->GetFullscreenPlayer()) {
65 gfx::ScopedJavaSurface scoped_surface(surface_texture);
66 player->SetVideoSurface(scoped_surface.Pass());
70 } // anonymous namespace
72 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl() {
75 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() {
78 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer(
79 base::ProcessHandle render_process_handle,
80 scoped_refptr<gfx::SurfaceTexture> surface_texture,
81 int render_frame_id,
82 int player_id) {
83 if (!surface_texture.get())
84 return;
86 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
87 &SetSurfacePeer, surface_texture, render_process_handle,
88 render_frame_id, player_id));
91 } // namespace content