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.
5 #include "content/browser/android/in_process_surface_texture_manager.h"
7 #include <android/native_window.h>
8 #include <android/native_window_jni.h>
10 #include "base/android/jni_android.h"
11 #include "base/containers/scoped_ptr_hash_map.h"
12 #include "base/logging.h"
13 #include "content/browser/media/android/browser_media_player_manager.h"
14 #include "content/public/browser/browser_thread.h"
19 InProcessSurfaceTextureManager
* InProcessSurfaceTextureManager::GetInstance() {
20 return base::Singleton
<
21 InProcessSurfaceTextureManager
,
22 base::LeakySingletonTraits
<InProcessSurfaceTextureManager
>>::get();
25 void InProcessSurfaceTextureManager::RegisterSurfaceTexture(
26 int surface_texture_id
,
28 gfx::SurfaceTexture
* surface_texture
) {
29 base::AutoLock
lock(lock_
);
31 DCHECK(surface_textures_
.find(surface_texture_id
) == surface_textures_
.end());
32 surface_textures_
.add(
34 make_scoped_ptr(new gfx::ScopedJavaSurface(surface_texture
)));
37 void InProcessSurfaceTextureManager::UnregisterSurfaceTexture(
38 int surface_texture_id
,
40 base::AutoLock
lock(lock_
);
42 DCHECK(surface_textures_
.find(surface_texture_id
) != surface_textures_
.end());
43 surface_textures_
.erase(surface_texture_id
);
46 gfx::AcceleratedWidget
47 InProcessSurfaceTextureManager::AcquireNativeWidgetForSurfaceTexture(
48 int surface_texture_id
) {
49 base::AutoLock
lock(lock_
);
51 DCHECK(surface_textures_
.find(surface_texture_id
) != surface_textures_
.end());
52 JNIEnv
* env
= base::android::AttachCurrentThread();
53 return ANativeWindow_fromSurface(
54 env
, surface_textures_
.get(surface_texture_id
)->j_surface().obj());
57 void InProcessSurfaceTextureManager::EstablishSurfaceTexturePeer(
58 base::ProcessHandle render_process_handle
,
59 scoped_refptr
<gfx::SurfaceTexture
> surface_texture
,
62 if (!surface_texture
.get())
65 BrowserThread::PostTask(
66 BrowserThread::UI
, FROM_HERE
,
67 base::Bind(&BrowserMediaPlayerManager::SetSurfacePeer
, surface_texture
,
68 render_process_handle
, render_frame_id
, player_id
));
71 InProcessSurfaceTextureManager::InProcessSurfaceTextureManager() {
72 SurfaceTexturePeer::InitInstance(this);
75 InProcessSurfaceTextureManager::~InProcessSurfaceTextureManager() {
76 SurfaceTexturePeer::InitInstance(nullptr);
79 } // namespace content