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