Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: content/browser/android/browser_surface_texture_manager.cc

Issue 634643002: content: Out-of-process GPU service support for SurfaceTexture backed GpuMemoryBuffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one last build fix Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.get());
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 content::CreateSurfaceTextureSurface(
88 surface_texture_id, client_id, surface_texture);
89 }
90
91 void BrowserSurfaceTextureManager::UnregisterSurfaceTexture(
92 int surface_texture_id,
93 int client_id) {
94 content::DestroySurfaceTextureSurface(surface_texture_id, client_id);
95 }
96
97 gfx::AcceleratedWidget BrowserSurfaceTextureManager::AcquireNativeWidget(
98 int surface_texture_id,
99 int client_id) {
100 gfx::ScopedJavaSurface surface(
101 content::GetSurfaceTextureSurface(surface_texture_id, client_id));
102 if (surface.j_surface().is_null())
103 return NULL;
104
105 JNIEnv* env = base::android::AttachCurrentThread();
106 // Note: This ensures that any local references used by
107 // ANativeWindow_fromSurface are released immediately. This is needed as a
108 // workaround for https://code.google.com/p/android/issues/detail?id=68174
109 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
110 ANativeWindow* native_window =
111 ANativeWindow_fromSurface(env, surface.j_surface().obj());
112
113 return native_window;
114 }
115
116 void BrowserSurfaceTextureManager::EstablishSurfaceTexturePeer(
117 base::ProcessHandle render_process_handle,
118 scoped_refptr<gfx::SurfaceTexture> surface_texture,
119 int render_frame_id,
120 int player_id) {
121 if (!surface_texture.get())
122 return;
123
124 BrowserThread::PostTask(BrowserThread::UI,
125 FROM_HERE,
126 base::Bind(&SetSurfacePeer,
127 surface_texture,
128 render_process_handle,
129 render_frame_id,
130 player_id));
131 }
132
133 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/browser_surface_texture_manager.h ('k') | content/browser/android/child_process_launcher_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698