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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser_main_loop.h" 5 #include "content/browser/browser_main_loop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 #if defined(USE_AURA) 72 #if defined(USE_AURA)
73 #include "content/public/browser/context_factory.h" 73 #include "content/public/browser/context_factory.h"
74 #include "ui/aura/env.h" 74 #include "ui/aura/env.h"
75 #endif 75 #endif
76 76
77 #if !defined(OS_IOS) 77 #if !defined(OS_IOS)
78 #include "content/browser/renderer_host/render_process_host_impl.h" 78 #include "content/browser/renderer_host/render_process_host_impl.h"
79 #endif 79 #endif
80 80
81 #if defined(OS_ANDROID) 81 #if defined(OS_ANDROID)
82 #include <android/native_window.h>
83 #include <android/native_window_jni.h>
84
82 #include "base/android/jni_android.h" 85 #include "base/android/jni_android.h"
86 #include "base/containers/scoped_ptr_hash_map.h"
87 #include "base/synchronization/lock.h"
83 #include "content/browser/android/browser_startup_controller.h" 88 #include "content/browser/android/browser_startup_controller.h"
84 #include "content/browser/android/browser_surface_texture_manager.h" 89 #include "content/browser/android/browser_surface_texture_manager.h"
85 #include "content/browser/android/tracing_controller_android.h" 90 #include "content/browser/android/tracing_controller_android.h"
86 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h" 91 #include "content/browser/screen_orientation/screen_orientation_delegate_android .h"
92 #include "content/common/android/surface_texture_manager.h"
87 #include "content/public/browser/screen_orientation_provider.h" 93 #include "content/public/browser/screen_orientation_provider.h"
94 #include "ui/gl/android/scoped_java_surface.h"
95 #include "ui/gl/android/surface_texture.h"
88 #include "ui/gl/gl_surface.h" 96 #include "ui/gl/gl_surface.h"
89 #endif 97 #endif
90 98
91 #if defined(OS_MACOSX) && !defined(OS_IOS) 99 #if defined(OS_MACOSX) && !defined(OS_IOS)
92 #include "base/mac/memory_pressure_monitor_mac.h" 100 #include "base/mac/memory_pressure_monitor_mac.h"
93 #include "content/browser/bootstrap_sandbox_mac.h" 101 #include "content/browser/bootstrap_sandbox_mac.h"
94 #include "content/browser/cocoa/system_hotkey_helper_mac.h" 102 #include "content/browser/cocoa/system_hotkey_helper_mac.h"
95 #include "content/browser/compositor/browser_compositor_view_mac.h" 103 #include "content/browser/compositor/browser_compositor_view_mac.h"
96 #include "content/browser/theme_helper_mac.h" 104 #include "content/browser/theme_helper_mac.h"
97 #endif 105 #endif
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 #endif 150 #endif
143 151
144 // One of the linux specific headers defines this as a macro. 152 // One of the linux specific headers defines this as a macro.
145 #ifdef DestroyAll 153 #ifdef DestroyAll
146 #undef DestroyAll 154 #undef DestroyAll
147 #endif 155 #endif
148 156
149 namespace content { 157 namespace content {
150 namespace { 158 namespace {
151 159
160 #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
161 class InProcessSurfaceTextureManager : public SurfaceTextureManager {
162 public:
163 InProcessSurfaceTextureManager() {}
164
165 // Overridden from SurfaceTextureManager:
166 void RegisterSurfaceTexture(int surface_texture_id,
167 int client_id,
168 gfx::SurfaceTexture* surface_texture) override {
169 base::AutoLock lock(lock_);
170 DCHECK(surfaces_.find(surface_texture_id) == surfaces_.end());
171 surfaces_.set(surface_texture_id,
172 make_scoped_ptr(new gfx::ScopedJavaSurface(surface_texture)));
173 }
174 void UnregisterSurfaceTexture(int surface_texture_id,
175 int client_id) override {
176 base::AutoLock lock(lock_);
177 DCHECK(surfaces_.find(surface_texture_id) != surfaces_.end());
178 surfaces_.erase(surface_texture_id);
179 }
180 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture(
181 int surface_texture_id) override {
182 base::AutoLock lock(lock_);
183 DCHECK(surfaces_.find(surface_texture_id) != surfaces_.end());
184 JNIEnv* env = base::android::AttachCurrentThread();
185 return ANativeWindow_fromSurface(
186 env, surfaces_.get(surface_texture_id)->j_surface().obj());
187 }
188
189 private:
190 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.
191 SurfaceMap;
192 SurfaceMap surfaces_;
193 base::Lock lock_;
194
195 DISALLOW_COPY_AND_ASSIGN(InProcessSurfaceTextureManager);
196 };
197
198 base::LazyInstance<InProcessSurfaceTextureManager>
199 g_in_process_surface_texture_manager = LAZY_INSTANCE_INITIALIZER;
200 #endif
201
152 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 202 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
153 void SetupSandbox(const base::CommandLine& parsed_command_line) { 203 void SetupSandbox(const base::CommandLine& parsed_command_line) {
154 TRACE_EVENT0("startup", "SetupSandbox"); 204 TRACE_EVENT0("startup", "SetupSandbox");
155 base::FilePath sandbox_binary; 205 base::FilePath sandbox_binary;
156 206
157 scoped_ptr<sandbox::SetuidSandboxHost> setuid_sandbox_host( 207 scoped_ptr<sandbox::SetuidSandboxHost> setuid_sandbox_host(
158 sandbox::SetuidSandboxHost::Create()); 208 sandbox::SetuidSandboxHost::Create());
159 209
160 const bool want_setuid_sandbox = 210 const bool want_setuid_sandbox =
161 !parsed_command_line.HasSwitch(switches::kNoSandbox) && 211 !parsed_command_line.HasSwitch(switches::kNoSandbox) &&
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // MessagePumpForUI::Start() as it will crash the browser. 607 // MessagePumpForUI::Start() as it will crash the browser.
558 if (is_tracing_startup_) { 608 if (is_tracing_startup_) {
559 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing"); 609 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing");
560 InitStartupTracing(parsed_command_line_); 610 InitStartupTracing(parsed_command_line_);
561 } 611 }
562 #endif // !defined(OS_IOS) 612 #endif // !defined(OS_IOS)
563 613
564 #if defined(OS_ANDROID) 614 #if defined(OS_ANDROID)
565 { 615 {
566 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); 616 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager");
567 SurfaceTextureManager::InitInstance(new BrowserSurfaceTextureManager); 617 browser_surface_texture_manager_.reset(new BrowserSurfaceTextureManager);
618 }
619
620 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
621 SurfaceTextureManager::InitInstance(
622 g_in_process_surface_texture_manager.Pointer());
623 } else {
624 SurfaceTextureManager::InitInstance(browser_surface_texture_manager_.get());
568 } 625 }
569 626
570 if (!parsed_command_line_.HasSwitch( 627 if (!parsed_command_line_.HasSwitch(
571 switches::kDisableScreenOrientationLock)) { 628 switches::kDisableScreenOrientationLock)) {
572 TRACE_EVENT0("startup", 629 TRACE_EVENT0("startup",
573 "BrowserMainLoop::Subsystem:ScreenOrientationProvider"); 630 "BrowserMainLoop::Subsystem:ScreenOrientationProvider");
574 screen_orientation_delegate_.reset( 631 screen_orientation_delegate_.reset(
575 new ScreenOrientationDelegateAndroid()); 632 new ScreenOrientationDelegateAndroid());
576 ScreenOrientationProvider::SetDelegate(screen_orientation_delegate_.get()); 633 ScreenOrientationProvider::SetDelegate(screen_orientation_delegate_.get());
577 } 634 }
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 1367
1311 void BrowserMainLoop::EndStartupTracing() { 1368 void BrowserMainLoop::EndStartupTracing() {
1312 is_tracing_startup_ = false; 1369 is_tracing_startup_ = false;
1313 TracingController::GetInstance()->DisableRecording( 1370 TracingController::GetInstance()->DisableRecording(
1314 TracingController::CreateFileSink( 1371 TracingController::CreateFileSink(
1315 startup_trace_file_, 1372 startup_trace_file_,
1316 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); 1373 base::Bind(OnStoppedStartupTracing, startup_trace_file_)));
1317 } 1374 }
1318 1375
1319 } // namespace content 1376 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698