OLD | NEW |
| (Empty) |
1 // Copyright 2015 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/in_process_surface_texture_manager.h" | |
6 | |
7 #include <android/native_window.h> | |
8 #include <android/native_window_jni.h> | |
9 | |
10 #include "base/android/jni_android.h" | |
11 #include "base/containers/scoped_ptr_hash_map.h" | |
12 #include "base/logging.h" | |
13 #include "base/memory/ptr_util.h" | |
14 #include "content/browser/media/android/browser_media_player_manager.h" | |
15 #include "content/public/browser/browser_thread.h" | |
16 | |
17 namespace content { | |
18 | |
19 // static | |
20 InProcessSurfaceTextureManager* InProcessSurfaceTextureManager::GetInstance() { | |
21 return base::Singleton< | |
22 InProcessSurfaceTextureManager, | |
23 base::LeakySingletonTraits<InProcessSurfaceTextureManager>>::get(); | |
24 } | |
25 | |
26 void InProcessSurfaceTextureManager::RegisterSurfaceTexture( | |
27 int surface_texture_id, | |
28 int client_id, | |
29 gfx::SurfaceTexture* surface_texture) { | |
30 base::AutoLock lock(lock_); | |
31 | |
32 DCHECK(surface_textures_.find(surface_texture_id) == surface_textures_.end()); | |
33 surface_textures_.add( | |
34 surface_texture_id, | |
35 base::WrapUnique(new gfx::ScopedJavaSurface(surface_texture))); | |
36 } | |
37 | |
38 void InProcessSurfaceTextureManager::UnregisterSurfaceTexture( | |
39 int surface_texture_id, | |
40 int client_id) { | |
41 base::AutoLock lock(lock_); | |
42 | |
43 DCHECK(surface_textures_.find(surface_texture_id) != surface_textures_.end()); | |
44 surface_textures_.erase(surface_texture_id); | |
45 } | |
46 | |
47 gfx::AcceleratedWidget | |
48 InProcessSurfaceTextureManager::AcquireNativeWidgetForSurfaceTexture( | |
49 int surface_texture_id) { | |
50 base::AutoLock lock(lock_); | |
51 | |
52 DCHECK(surface_textures_.find(surface_texture_id) != surface_textures_.end()); | |
53 JNIEnv* env = base::android::AttachCurrentThread(); | |
54 return ANativeWindow_fromSurface( | |
55 env, surface_textures_.get(surface_texture_id)->j_surface().obj()); | |
56 } | |
57 | |
58 void InProcessSurfaceTextureManager::EstablishSurfaceTexturePeer( | |
59 base::ProcessHandle render_process_handle, | |
60 scoped_refptr<gfx::SurfaceTexture> surface_texture, | |
61 int render_frame_id, | |
62 int player_id) { | |
63 if (!surface_texture.get()) | |
64 return; | |
65 | |
66 BrowserThread::PostTask( | |
67 BrowserThread::UI, FROM_HERE, | |
68 base::Bind(&BrowserMediaPlayerManager::SetSurfacePeer, surface_texture, | |
69 render_process_handle, render_frame_id, player_id)); | |
70 } | |
71 | |
72 InProcessSurfaceTextureManager::InProcessSurfaceTextureManager() { | |
73 SurfaceTexturePeer::InitInstance(this); | |
74 } | |
75 | |
76 InProcessSurfaceTextureManager::~InProcessSurfaceTextureManager() { | |
77 SurfaceTexturePeer::InitInstance(nullptr); | |
78 } | |
79 | |
80 } // namespace content | |
OLD | NEW |