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

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: Make InProcessSurfaceTextureManager thread safe Created 5 years, 7 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 17c6ebedb1ff5c38473b8ce8f60fdef1305d5d12..afec0a5e79fb9987ce0c66413d180c79bd63099f 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -79,12 +79,20 @@
#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/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 +157,48 @@
namespace content {
namespace {
+#if defined(OS_ANDROID)
Daniele Castagna 2015/05/06 18:39:41 Could this class be somewhere else?
reveman 2015/05/06 20:37:47 I'm Ok with leaving it here or moving it somewhere
+class InProcessSurfaceTextureManager : public SurfaceTextureManager {
+ public:
+ InProcessSurfaceTextureManager() {}
+
+ // 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());
+ 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());
+ JNIEnv* env = base::android::AttachCurrentThread();
+ return ANativeWindow_fromSurface(
+ env, surfaces_.get(surface_texture_id)->j_surface().obj());
+ }
+
+ private:
+ typedef base::ScopedPtrHashMap<int, scoped_ptr<gfx::ScopedJavaSurface>>
Daniele Castagna 2015/05/06 18:39:41 Is there something like a ConcurrentMap so you can
reveman 2015/05/06 20:37:47 Not that I know.
+ SurfaceMap;
+ SurfaceMap surfaces_;
+ base::Lock lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(InProcessSurfaceTextureManager);
+};
+
+base::LazyInstance<InProcessSurfaceTextureManager>
+ g_in_process_surface_texture_manager = LAZY_INSTANCE_INITIALIZER;
+#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 +614,14 @@ void BrowserMainLoop::MainMessageLoopStart() {
#if defined(OS_ANDROID)
{
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager");
- SurfaceTextureManager::InitInstance(new BrowserSurfaceTextureManager);
+ browser_surface_texture_manager_.reset(new BrowserSurfaceTextureManager);
+ }
+
+ if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) {
Daniele Castagna 2015/05/06 18:39:41 This shouldn't be true on any real platform, right
reveman 2015/05/06 20:37:47 It's always the true on Android Webview and it wil
+ SurfaceTextureManager::InitInstance(
+ g_in_process_surface_texture_manager.Pointer());
+ } else {
+ SurfaceTextureManager::InitInstance(browser_surface_texture_manager_.get());
}
if (!parsed_command_line_.HasSwitch(

Powered by Google App Engine
This is Rietveld 408576698