| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/android/browser_surface_texture_manager.h" | 5 #include "content/browser/android/browser_surface_texture_manager.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "content/browser/android/child_process_launcher_android.h" | 10 #include "content/browser/android/child_process_launcher_android.h" |
| 11 #include "content/browser/frame_host/render_frame_host_impl.h" | 11 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 12 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 12 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 13 #include "content/browser/media/android/browser_media_player_manager.h" | 13 #include "content/browser/media/android/browser_media_player_manager.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "ui/gl/android/scoped_java_surface.h" | 15 #include "ui/gl/android/scoped_java_surface.h" |
| 16 #include "ui/gl/android/surface_texture.h" | 16 #include "ui/gl/android/surface_texture.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 BrowserSurfaceTextureManager* BrowserSurfaceTextureManager::GetInstance() { | 21 BrowserSurfaceTextureManager* BrowserSurfaceTextureManager::GetInstance() { |
| 22 return base::Singleton< | 22 return base::Singleton< |
| 23 BrowserSurfaceTextureManager, | 23 BrowserSurfaceTextureManager, |
| 24 base::LeakySingletonTraits<BrowserSurfaceTextureManager>>::get(); | 24 base::LeakySingletonTraits<BrowserSurfaceTextureManager>>::get(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void BrowserSurfaceTextureManager::RegisterSurfaceTexture( | 27 void BrowserSurfaceTextureManager::RegisterSurfaceTexture( |
| 28 int surface_texture_id, | 28 int surface_texture_id, |
| 29 int client_id, | 29 int client_id, |
| 30 gfx::SurfaceTexture* surface_texture) { | 30 gl::SurfaceTexture* surface_texture) { |
| 31 content::CreateSurfaceTextureSurface( | 31 content::CreateSurfaceTextureSurface( |
| 32 surface_texture_id, client_id, surface_texture); | 32 surface_texture_id, client_id, surface_texture); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void BrowserSurfaceTextureManager::UnregisterSurfaceTexture( | 35 void BrowserSurfaceTextureManager::UnregisterSurfaceTexture( |
| 36 int surface_texture_id, | 36 int surface_texture_id, |
| 37 int client_id) { | 37 int client_id) { |
| 38 content::DestroySurfaceTextureSurface(surface_texture_id, client_id); | 38 content::DestroySurfaceTextureSurface(surface_texture_id, client_id); |
| 39 } | 39 } |
| 40 | 40 |
| 41 gfx::AcceleratedWidget | 41 gfx::AcceleratedWidget |
| 42 BrowserSurfaceTextureManager::AcquireNativeWidgetForSurfaceTexture( | 42 BrowserSurfaceTextureManager::AcquireNativeWidgetForSurfaceTexture( |
| 43 int surface_texture_id) { | 43 int surface_texture_id) { |
| 44 gfx::ScopedJavaSurface surface( | 44 gl::ScopedJavaSurface surface(content::GetSurfaceTextureSurface( |
| 45 content::GetSurfaceTextureSurface( | 45 surface_texture_id, |
| 46 surface_texture_id, | 46 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId())); |
| 47 BrowserGpuChannelHostFactory::instance()->GetGpuChannelId())); | |
| 48 if (surface.j_surface().is_null()) | 47 if (surface.j_surface().is_null()) |
| 49 return NULL; | 48 return NULL; |
| 50 | 49 |
| 51 JNIEnv* env = base::android::AttachCurrentThread(); | 50 JNIEnv* env = base::android::AttachCurrentThread(); |
| 52 // Note: This ensures that any local references used by | 51 // Note: This ensures that any local references used by |
| 53 // ANativeWindow_fromSurface are released immediately. This is needed as a | 52 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| 54 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 53 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
| 55 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 54 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 56 ANativeWindow* native_window = | 55 ANativeWindow* native_window = |
| 57 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | 56 ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
| 58 | 57 |
| 59 return native_window; | 58 return native_window; |
| 60 } | 59 } |
| 61 | 60 |
| 62 BrowserSurfaceTextureManager::BrowserSurfaceTextureManager() { | 61 BrowserSurfaceTextureManager::BrowserSurfaceTextureManager() { |
| 63 } | 62 } |
| 64 | 63 |
| 65 BrowserSurfaceTextureManager::~BrowserSurfaceTextureManager() { | 64 BrowserSurfaceTextureManager::~BrowserSurfaceTextureManager() { |
| 66 } | 65 } |
| 67 | 66 |
| 68 } // namespace content | 67 } // namespace content |
| OLD | NEW |