Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / android / in_process_surface_texture_manager.cc
blob4a5f698644ba83792a5728a00d998e4ec073b10e
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 Singleton<InProcessSurfaceTextureManager,
21 LeakySingletonTraits<InProcessSurfaceTextureManager>>::get();
24 void InProcessSurfaceTextureManager::RegisterSurfaceTexture(
25 int surface_texture_id,
26 int client_id,
27 gfx::SurfaceTexture* surface_texture) {
28 base::AutoLock lock(lock_);
30 DCHECK(surface_textures_.find(surface_texture_id) == surface_textures_.end());
31 surface_textures_.add(
32 surface_texture_id,
33 make_scoped_ptr(new gfx::ScopedJavaSurface(surface_texture)));
36 void InProcessSurfaceTextureManager::UnregisterSurfaceTexture(
37 int surface_texture_id,
38 int client_id) {
39 base::AutoLock lock(lock_);
41 DCHECK(surface_textures_.find(surface_texture_id) != surface_textures_.end());
42 surface_textures_.erase(surface_texture_id);
45 gfx::AcceleratedWidget
46 InProcessSurfaceTextureManager::AcquireNativeWidgetForSurfaceTexture(
47 int surface_texture_id) {
48 base::AutoLock lock(lock_);
50 DCHECK(surface_textures_.find(surface_texture_id) != surface_textures_.end());
51 JNIEnv* env = base::android::AttachCurrentThread();
52 return ANativeWindow_fromSurface(
53 env, surface_textures_.get(surface_texture_id)->j_surface().obj());
56 void InProcessSurfaceTextureManager::EstablishSurfaceTexturePeer(
57 base::ProcessHandle render_process_handle,
58 scoped_refptr<gfx::SurfaceTexture> surface_texture,
59 int render_frame_id,
60 int player_id) {
61 if (!surface_texture.get())
62 return;
64 BrowserThread::PostTask(
65 BrowserThread::UI, FROM_HERE,
66 base::Bind(&BrowserMediaPlayerManager::SetSurfacePeer, surface_texture,
67 render_process_handle, render_frame_id, player_id));
70 InProcessSurfaceTextureManager::InProcessSurfaceTextureManager() {
71 SurfaceTexturePeer::InitInstance(this);
74 InProcessSurfaceTextureManager::~InProcessSurfaceTextureManager() {
75 SurfaceTexturePeer::InitInstance(nullptr);
78 } // namespace content