Chromium Code Reviews| Index: content/browser/browser_main_loop.cc |
| diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc |
| index 17c6ebedb1ff5c38473b8ce8f60fdef1305d5d12..9e9196e572517aa690b0a371a27cf56c7f46a713 100644 |
| --- a/content/browser/browser_main_loop.cc |
| +++ b/content/browser/browser_main_loop.cc |
| @@ -79,12 +79,21 @@ |
| #endif |
| #if defined(OS_ANDROID) |
| +#include <android/native_window.h> |
| +#include <android/native_window_jni.h> |
| + |
| #include "base/android/jni_android.h" |
| +#include "base/containers/scoped_ptr_hash_map.h" |
| +#include "base/synchronization/lock.h" |
| #include "content/browser/android/browser_startup_controller.h" |
| #include "content/browser/android/browser_surface_texture_manager.h" |
| #include "content/browser/android/tracing_controller_android.h" |
| #include "content/browser/screen_orientation/screen_orientation_delegate_android.h" |
| +#include "content/common/android/surface_texture_manager.h" |
| +#include "content/common/android/surface_texture_peer.h" |
| #include "content/public/browser/screen_orientation_provider.h" |
| +#include "ui/gl/android/scoped_java_surface.h" |
| +#include "ui/gl/android/surface_texture.h" |
| #include "ui/gl/gl_surface.h" |
| #endif |
| @@ -149,6 +158,58 @@ |
| namespace content { |
| namespace { |
| +#if defined(OS_ANDROID) |
| +class InProcessSurfaceTextureManager : public SurfaceTextureManager, |
| + public SurfaceTexturePeer { |
| + public: |
| + InProcessSurfaceTextureManager() { SurfaceTexturePeer::InitInstance(this); } |
| + ~InProcessSurfaceTextureManager() override { |
| + SurfaceTexturePeer::InitInstance(NULL); |
| + } |
| + |
| + // Overridden from SurfaceTextureManager: |
| + void RegisterSurfaceTexture(int surface_texture_id, |
| + int client_id, |
| + gfx::SurfaceTexture* surface_texture) override { |
| + base::AutoLock lock(lock_); |
| + DCHECK(surfaces_.find(surface_texture_id) == surfaces_.end()); |
| + surfaces_.set(surface_texture_id, |
| + make_scoped_ptr(new gfx::ScopedJavaSurface(surface_texture))); |
| + } |
| + void UnregisterSurfaceTexture(int surface_texture_id, |
| + int client_id) override { |
| + base::AutoLock lock(lock_); |
| + DCHECK(surfaces_.find(surface_texture_id) != surfaces_.end()); |
|
Daniele Castagna
2015/05/06 20:46:26
nit: DCHECK_EQ should be preferred.
reveman
2015/06/08 22:20:48
doesn't work with that macro
|
| + surfaces_.erase(surface_texture_id); |
| + } |
| + gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( |
| + int surface_texture_id) override { |
| + base::AutoLock lock(lock_); |
| + DCHECK(surfaces_.find(surface_texture_id) != surfaces_.end()); |
|
Daniele Castagna
2015/05/06 20:46:26
Same here: DCHECK_NE
reveman
2015/06/08 22:20:48
same
|
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + return ANativeWindow_fromSurface( |
| + env, surfaces_.get(surface_texture_id)->j_surface().obj()); |
|
Daniele Castagna
2015/05/06 20:46:26
You can use surfaces_->operator[] if you prefer.
reveman
2015/06/08 22:20:48
kept use get() of get to be consistent with code i
|
| + } |
| + |
| + // Overridden from SurfaceTexturePeer: |
| + void EstablishSurfaceTexturePeer( |
| + base::ProcessHandle render_process_handle, |
| + scoped_refptr<gfx::SurfaceTexture> surface_texture, |
| + int render_frame_id, |
| + int player_id) override { |
| + NOTIMPLEMENTED(); |
| + } |
| + |
| + private: |
| + typedef base::ScopedPtrHashMap<int, scoped_ptr<gfx::ScopedJavaSurface>> |
| + SurfaceMap; |
| + SurfaceMap surfaces_; |
| + base::Lock lock_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(InProcessSurfaceTextureManager); |
| +}; |
| +#endif |
| + |
| #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| void SetupSandbox(const base::CommandLine& parsed_command_line) { |
| TRACE_EVENT0("startup", "SetupSandbox"); |
| @@ -564,7 +625,10 @@ void BrowserMainLoop::MainMessageLoopStart() { |
| #if defined(OS_ANDROID) |
| { |
| TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); |
| - SurfaceTextureManager::InitInstance(new BrowserSurfaceTextureManager); |
| + if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) |
| + SurfaceTextureManager::InitInstance(new InProcessSurfaceTextureManager); |
| + else |
| + SurfaceTextureManager::InitInstance(new BrowserSurfaceTextureManager); |
| } |
| if (!parsed_command_line_.HasSwitch( |