[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / android / in_process_surface_texture_manager.cc
blob23dc67c2e8ced942561f4bbde44c01daccd3706a
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"
16 namespace content {
18 // static
19 InProcessSurfaceTextureManager* InProcessSurfaceTextureManager::GetInstance() {
20 return base::Singleton<
21 InProcessSurfaceTextureManager,
22 base::LeakySingletonTraits<InProcessSurfaceTextureManager>>::get();
25 void InProcessSurfaceTextureManager::RegisterSurfaceTexture(
26 int surface_texture_id,
27 int client_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(
33 surface_texture_id,
34 make_scoped_ptr(new gfx::ScopedJavaSurface(surface_texture)));
37 void InProcessSurfaceTextureManager::UnregisterSurfaceTexture(
38 int surface_texture_id,
39 int client_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,
60 int render_frame_id,
61 int player_id) {
62 if (!surface_texture.get())
63 return;
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