OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/browser_surface_texture_manager.h" | |
6 | |
7 #include <android/native_window_jni.h> | |
8 | |
9 #include "base/android/jni_android.h" | |
10 #include "content/browser/android/child_process_launcher_android.h" | |
11 #include "content/browser/frame_host/render_frame_host_impl.h" | |
12 #include "content/browser/media/android/browser_media_player_manager.h" | |
13 #include "content/browser/media/media_web_contents_observer.h" | |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | |
15 #include "content/public/browser/browser_thread.h" | |
16 #include "content/public/browser/render_process_host.h" | |
17 #include "media/base/android/media_player_android.h" | |
18 #include "ui/gl/android/scoped_java_surface.h" | |
19 #include "ui/gl/android/surface_texture.h" | |
20 | |
21 namespace content { | |
22 namespace { | |
23 | |
24 // Pass a java surface object to the MediaPlayerAndroid object | |
25 // identified by render process handle, render frame ID and player ID. | |
26 static void SetSurfacePeer(scoped_refptr<gfx::SurfaceTexture> surface_texture, | |
27 base::ProcessHandle render_process_handle, | |
28 int render_frame_id, | |
29 int player_id) { | |
30 int render_process_id = 0; | |
31 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | |
32 while (!it.IsAtEnd()) { | |
33 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { | |
34 render_process_id = it.GetCurrentValue()->GetID(); | |
35 break; | |
36 } | |
37 it.Advance(); | |
38 } | |
39 if (!render_process_id) { | |
40 DVLOG(1) << "Cannot find render process for render_process_handle " | |
41 << render_process_handle; | |
42 return; | |
43 } | |
44 | |
45 RenderFrameHostImpl* frame = | |
46 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | |
47 if (!frame) { | |
48 DVLOG(1) << "Cannot find frame for render_frame_id " << render_frame_id; | |
49 return; | |
50 } | |
51 | |
52 RenderViewHostImpl* view = | |
53 static_cast<RenderViewHostImpl*>(frame->GetRenderViewHost()); | |
54 BrowserMediaPlayerManager* player_manager = | |
55 view->media_web_contents_observer()->GetMediaPlayerManager(frame); | |
56 if (!player_manager) { | |
57 DVLOG(1) << "Cannot find the media player manager for frame " << frame; | |
58 return; | |
59 } | |
60 | |
61 media::MediaPlayerAndroid* player = player_manager->GetPlayer(player_id); | |
62 if (!player) { | |
63 DVLOG(1) << "Cannot find media player for player_id " << player_id; | |
64 return; | |
65 } | |
66 | |
67 if (player != player_manager->GetFullscreenPlayer()) { | |
68 gfx::ScopedJavaSurface scoped_surface(surface_texture); | |
69 player->SetVideoSurface(scoped_surface.Pass()); | |
70 } | |
71 } | |
72 | |
73 } // namespace | |
74 | |
75 BrowserSurfaceTextureManager::BrowserSurfaceTextureManager() { | |
76 SurfaceTexturePeer::InitInstance(this); | |
77 } | |
78 | |
79 BrowserSurfaceTextureManager::~BrowserSurfaceTextureManager() { | |
80 SurfaceTexturePeer::InitInstance(NULL); | |
81 } | |
82 | |
83 void BrowserSurfaceTextureManager::RegisterSurfaceTexture( | |
84 int surface_texture_id, | |
85 int client_id, | |
86 gfx::SurfaceTexture* surface_texture) { | |
87 gfx::ScopedJavaSurface surface(surface_texture); | |
no sievers
2014/10/07 22:12:45
Does the surface still work when you pass it to Ja
reveman
2014/10/08 15:56:39
Ah, I was too quick to change this without actuall
| |
88 content::RegisterSurfaceTextureSurface( | |
89 surface_texture_id, client_id, surface.j_surface().obj()); | |
90 } | |
91 | |
92 void BrowserSurfaceTextureManager::UnregisterSurfaceTexture( | |
93 int surface_texture_id, | |
94 int client_id) { | |
95 content::UnregisterSurfaceTextureSurface(surface_texture_id, client_id); | |
96 } | |
97 | |
98 gfx::AcceleratedWidget BrowserSurfaceTextureManager::AcquireNativeWidget( | |
99 int surface_texture_id, | |
100 int client_id) { | |
101 gfx::ScopedJavaSurface surface( | |
no sievers
2014/10/07 22:12:45
Similar problem here. I think it works the first t
reveman
2014/10/08 15:56:39
Nice catch. Should be fixed in latest patch. Inclu
| |
102 content::GetSurfaceTextureSurface(surface_texture_id, client_id)); | |
103 if (surface.j_surface().is_null()) | |
104 return NULL; | |
105 | |
106 JNIEnv* env = base::android::AttachCurrentThread(); | |
107 // Note: This ensures that any local references used by | |
108 // ANativeWindow_fromSurface are released immediately. This is needed as a | |
109 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | |
110 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | |
111 ANativeWindow* native_window = | |
112 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | |
113 | |
114 return native_window; | |
115 } | |
116 | |
117 void BrowserSurfaceTextureManager::EstablishSurfaceTexturePeer( | |
118 base::ProcessHandle render_process_handle, | |
119 scoped_refptr<gfx::SurfaceTexture> surface_texture, | |
120 int render_frame_id, | |
121 int player_id) { | |
122 if (!surface_texture.get()) | |
123 return; | |
124 | |
125 BrowserThread::PostTask(BrowserThread::UI, | |
126 FROM_HERE, | |
127 base::Bind(&SetSurfacePeer, | |
128 surface_texture, | |
129 render_process_handle, | |
130 render_frame_id, | |
131 player_id)); | |
132 } | |
133 | |
134 } // namespace content | |
OLD | NEW |