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

Side by Side Diff: services/native_viewport/native_viewport_app.cc

Issue 2011383002: Get rid of {Run,Terminate}MainApplication(), and more ApplicationDelegate conversion. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "services/native_viewport/app_delegate.h" 5 #include "services/native_viewport/native_viewport_app.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "gpu/config/gpu_util.h" 9 #include "gpu/config/gpu_util.h"
10 #include "mojo/public/cpp/application/service_provider_impl.h"
11 #include "mojo/services/native_viewport/cpp/args.h"
12 #include "services/gles2/gpu_impl.h"
13 #include "services/native_viewport/native_viewport_impl.h"
14 #include "ui/events/event_switches.h"
15 #include "ui/gl/gl_surface.h"
10 16
11 namespace native_viewport { 17 namespace native_viewport {
12 18
13 NativeViewportAppDelegate::NativeViewportAppDelegate() : is_headless_(false) {} 19 NativeViewportApp::NativeViewportApp() : is_headless_(false) {}
14 20
15 NativeViewportAppDelegate::~NativeViewportAppDelegate() {} 21 NativeViewportApp::~NativeViewportApp() {}
16 22
17 void NativeViewportAppDelegate::InitLogging( 23 void NativeViewportApp::OnInitialize() {
18 mojo::ApplicationImpl* application) { 24 InitLogging();
19 std::vector<const char*> args; 25 tracing_.Initialize(shell(), &args());
20 for (auto& a : application->args()) {
21 args.push_back(a.c_str());
22 }
23
24 base::CommandLine::Reset();
25 base::CommandLine::Init(args.size(), args.data());
26
27 logging::LoggingSettings settings;
28 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
29 logging::InitLogging(settings);
30 }
31
32 void NativeViewportAppDelegate::Initialize(mojo::ApplicationImpl* application) {
33 application_ = application;
34
35 InitLogging(application);
36 tracing_.Initialize(application->shell(), &application->args());
37 26
38 // Apply the switch for kTouchEvents to CommandLine (if set). This allows 27 // Apply the switch for kTouchEvents to CommandLine (if set). This allows
39 // redirecting the mouse to a touch device on X for testing. 28 // redirecting the mouse to a touch device on X for testing.
40 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 29 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
41 const std::string touch_event_string("--" + 30 const std::string touch_event_string("--" +
42 std::string(switches::kTouchDevices)); 31 std::string(switches::kTouchDevices));
43 auto touch_iter = std::find(application->args().begin(), 32 auto touch_iter = std::find(args().begin(), args().end(), touch_event_string);
44 application->args().end(), touch_event_string); 33 if (touch_iter != args().end() && ++touch_iter != args().end())
45 if (touch_iter != application->args().end() &&
46 ++touch_iter != application->args().end()) {
47 command_line->AppendSwitchASCII(touch_event_string, *touch_iter); 34 command_line->AppendSwitchASCII(touch_event_string, *touch_iter);
48 }
49 35
50 gpu::ApplyGpuDriverBugWorkarounds(command_line); 36 gpu::ApplyGpuDriverBugWorkarounds(command_line);
51 37
52 if (application->HasArg(mojo::kUseTestConfig)) 38 if (HasArg(mojo::kUseTestConfig))
53 gfx::GLSurface::InitializeOneOffForTests(); 39 gfx::GLSurface::InitializeOneOffForTests();
54 else if (application->HasArg(mojo::kUseOSMesa)) 40 else if (HasArg(mojo::kUseOSMesa))
55 gfx::GLSurface::InitializeOneOff(gfx::kGLImplementationOSMesaGL); 41 gfx::GLSurface::InitializeOneOff(gfx::kGLImplementationOSMesaGL);
56 else 42 else
57 gfx::GLSurface::InitializeOneOff(); 43 gfx::GLSurface::InitializeOneOff();
58 44
59 is_headless_ = application->HasArg(mojo::kUseHeadlessConfig); 45 is_headless_ = HasArg(mojo::kUseHeadlessConfig);
60 } 46 }
61 47
62 bool NativeViewportAppDelegate::ConfigureIncomingConnection( 48 bool NativeViewportApp::OnAcceptConnection(
63 mojo::ServiceProviderImpl* service_provider_impl) { 49 mojo::ServiceProviderImpl* service_provider_impl) {
64 service_provider_impl->AddService<mojo::NativeViewport>([this]( 50 service_provider_impl->AddService<mojo::NativeViewport>([this](
65 const mojo::ConnectionContext& connection_context, 51 const mojo::ConnectionContext& connection_context,
66 mojo::InterfaceRequest<mojo::NativeViewport> native_viewport_request) { 52 mojo::InterfaceRequest<mojo::NativeViewport> native_viewport_request) {
67 if (!gpu_state_.get()) 53 if (!gpu_state_.get())
68 gpu_state_ = new gles2::GpuState(); 54 gpu_state_ = new gles2::GpuState();
69 new NativeViewportImpl(application_->shell(), is_headless_, gpu_state_, 55 new NativeViewportImpl(shell(), is_headless_, gpu_state_,
70 native_viewport_request.Pass()); 56 native_viewport_request.Pass());
71 }); 57 });
72 58
73 service_provider_impl->AddService<mojo::Gpu>( 59 service_provider_impl->AddService<mojo::Gpu>(
74 [this](const mojo::ConnectionContext& connection_context, 60 [this](const mojo::ConnectionContext& connection_context,
75 mojo::InterfaceRequest<mojo::Gpu> gpu_request) { 61 mojo::InterfaceRequest<mojo::Gpu> gpu_request) {
76 if (!gpu_state_.get()) 62 if (!gpu_state_.get())
77 gpu_state_ = new gles2::GpuState(); 63 gpu_state_ = new gles2::GpuState();
78 new gles2::GpuImpl(gpu_request.Pass(), gpu_state_); 64 new gles2::GpuImpl(gpu_request.Pass(), gpu_state_);
79 }); 65 });
80 66
81 return true; 67 return true;
82 } 68 }
83 69
70 void NativeViewportApp::InitLogging() {
71 std::vector<const char*> argv;
72 for (const auto& a : args())
73 argv.push_back(a.c_str());
74
75 base::CommandLine::Reset();
76 base::CommandLine::Init(argv.size(), argv.data());
77
78 logging::LoggingSettings settings;
79 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
80 logging::InitLogging(settings);
81 }
82
84 } // namespace native_viewport 83 } // namespace native_viewport
OLDNEW
« no previous file with comments | « services/native_viewport/native_viewport_app.h ('k') | services/native_viewport/ozone/app_delegate_ozone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698