Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(987)

Unified Diff: content/browser/browser_main_loop.cc

Issue 1120873002: Re-land: content: Single process support for native GpuMemoryBuffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dm-browsertests-refactor
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/browser_main_loop.cc
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index 9ed607ac11baf8ef88141b47e6d8e804d1a29acc..8fee3c7140506ff95e9faa71340f0ef1e0384be3 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -83,12 +83,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/memory/singleton.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/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
@@ -97,12 +106,17 @@
#endif
#if defined(OS_MACOSX) && !defined(OS_IOS)
+#include "base/containers/scoped_ptr_hash_map.h"
+#include "base/mac/scoped_mach_port.h"
#include "base/memory/memory_pressure_monitor_mac.h"
+#include "base/memory/singleton.h"
+#include "base/synchronization/lock.h"
#include "content/browser/bootstrap_sandbox_mac.h"
#include "content/browser/browser_io_surface_manager_mac.h"
#include "content/browser/cocoa/system_hotkey_helper_mac.h"
#include "content/browser/compositor/browser_compositor_view_mac.h"
#include "content/browser/theme_helper_mac.h"
+#include "content/common/mac/io_surface_manager.h"
#endif
#if defined(OS_WIN)
@@ -159,6 +173,93 @@
namespace content {
namespace {
+#if defined(OS_ANDROID)
+class InProcessSurfaceTextureManager : public SurfaceTextureManager {
Daniele Castagna 2015/06/09 14:45:07 I still think these two classes should live somewh
reveman 2015/06/09 17:48:14 Done.
+ public:
+ static InProcessSurfaceTextureManager* GetInstance() {
+ return Singleton<
+ InProcessSurfaceTextureManager,
+ LeakySingletonTraits<InProcessSurfaceTextureManager>>::get();
+ }
+
+ // Overridden from SurfaceTextureManager:
+ void RegisterSurfaceTexture(int surface_texture_id,
+ int client_id,
+ gfx::SurfaceTexture* surface_texture) override {
+ base::AutoLock lock(lock_);
+ DCHECK(surface_textures_.find(surface_texture_id) ==
Daniele Castagna 2015/06/09 14:45:07 nit: DCHECK(!bla.contains()).
reveman 2015/06/09 17:48:14 Kept the existing DCHECK to be consistent with Bro
+ surface_textures_.end());
+ surface_textures_.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(surface_textures_.find(surface_texture_id) !=
Daniele Castagna 2015/06/09 14:45:06 nit: same as above.
reveman 2015/06/09 17:48:14 ditto
+ surface_textures_.end());
+ surface_textures_.erase(surface_texture_id);
+ }
+ gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture(
+ int surface_texture_id) override {
+ base::AutoLock lock(lock_);
+ DCHECK(surface_textures_.find(surface_texture_id) !=
+ surface_textures_.end());
+ JNIEnv* env = base::android::AttachCurrentThread();
+ return ANativeWindow_fromSurface(
+ env, surface_textures_.get(surface_texture_id)->j_surface().obj());
+ }
+
+ private:
+ friend struct DefaultSingletonTraits<InProcessSurfaceTextureManager>;
+
+ using SurfaceTextureMap =
+ base::ScopedPtrHashMap<int, scoped_ptr<gfx::ScopedJavaSurface>>;
+ SurfaceTextureMap surface_textures_;
+ base::Lock lock_;
+};
+#endif
+
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+class InProcessIOSurfaceManager : public IOSurfaceManager {
+ public:
+ static InProcessIOSurfaceManager* GetInstance() {
+ return Singleton<InProcessIOSurfaceManager,
+ LeakySingletonTraits<InProcessIOSurfaceManager>>::get();
+ }
+
+ // Overridden from IOSurfaceManager:
+ bool RegisterIOSurface(int io_surface_id,
+ int client_id,
+ IOSurfaceRef io_surface) override {
+ base::AutoLock lock(lock_);
+ DCHECK(io_surfaces_.find(io_surface_id) == io_surfaces_.end());
+ io_surfaces_.add(io_surface_id,
+ make_scoped_ptr(new base::mac::ScopedMachSendRight(
+ IOSurfaceCreateMachPort(io_surface))));
+ return true;
+ }
+ void UnregisterIOSurface(int io_surface_id, int client_id) override {
+ base::AutoLock lock(lock_);
+ DCHECK(io_surfaces_.find(io_surface_id) != io_surfaces_.end());
+ io_surfaces_.erase(io_surface_id);
+ }
+ IOSurfaceRef AcquireIOSurface(int io_surface_id) override {
+ base::AutoLock lock(lock_);
+ DCHECK(io_surfaces_.find(io_surface_id) != io_surfaces_.end());
+ return IOSurfaceLookupFromMachPort(io_surfaces_.get(io_surface_id)->get());
+ }
+
+ private:
+ friend struct DefaultSingletonTraits<InProcessIOSurfaceManager>;
+
+ using IOSurfaceMap =
+ base::ScopedPtrHashMap<int, scoped_ptr<base::mac::ScopedMachSendRight>>;
+ IOSurfaceMap io_surfaces_;
+ base::Lock lock_;
+};
+#endif
+
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
void SetupSandbox(const base::CommandLine& parsed_command_line) {
TRACE_EVENT0("startup", "SetupSandbox");
@@ -589,7 +690,13 @@ void BrowserMainLoop::PostMainMessageLoopStart() {
#if defined(OS_ANDROID)
{
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager");
- SurfaceTextureManager::SetInstance(new BrowserSurfaceTextureManager);
+ if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) {
+ SurfaceTextureManager::SetInstance(
+ InProcessSurfaceTextureManager::GetInstance());
+ } else {
+ SurfaceTextureManager::SetInstance(
+ BrowserSurfaceTextureManager::GetInstance());
+ }
}
if (!parsed_command_line_.HasSwitch(
@@ -605,7 +712,11 @@ void BrowserMainLoop::PostMainMessageLoopStart() {
#if defined(OS_MACOSX) && !defined(OS_IOS)
{
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:IOSurfaceManager");
- IOSurfaceManager::SetInstance(BrowserIOSurfaceManager::GetInstance());
+ if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) {
+ IOSurfaceManager::SetInstance(InProcessIOSurfaceManager::GetInstance());
+ } else {
+ IOSurfaceManager::SetInstance(BrowserIOSurfaceManager::GetInstance());
+ }
}
#endif
« no previous file with comments | « content/browser/android/browser_surface_texture_manager.cc ('k') | content/child/child_thread_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698