OLD | NEW |
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 <algorithm> | 5 #if defined(USE_OZONE) |
6 | 6 #include "services/native_viewport/ozone/app_delegate_ozone.h" |
7 #include "base/command_line.h" | 7 #else |
8 #include "base/macros.h" | 8 #include "services/native_viewport/app_delegate.h" |
9 #include "base/message_loop/message_loop.h" | 9 #endif |
10 #include "mojo/application/application_runner_chromium.h" | |
11 #include "mojo/common/tracing_impl.h" | |
12 #include "mojo/public/c/system/main.h" | |
13 #include "mojo/public/cpp/application/application_connection.h" | |
14 #include "mojo/public/cpp/application/application_delegate.h" | |
15 #include "mojo/public/cpp/application/application_impl.h" | |
16 #include "mojo/public/cpp/application/interface_factory_impl.h" | |
17 #include "mojo/services/native_viewport/public/cpp/args.h" | |
18 #include "services/gles2/gpu_impl.h" | |
19 #include "services/native_viewport/native_viewport_impl.h" | |
20 #include "ui/events/event_switches.h" | |
21 #include "ui/gl/gl_surface.h" | |
22 | |
23 using mojo::ApplicationConnection; | |
24 using mojo::Gpu; | |
25 using mojo::NativeViewport; | |
26 | |
27 namespace native_viewport { | |
28 | |
29 class NativeViewportAppDelegate : public mojo::ApplicationDelegate, | |
30 public mojo::InterfaceFactory<NativeViewport>, | |
31 public mojo::InterfaceFactory<Gpu> { | |
32 public: | |
33 NativeViewportAppDelegate() : is_headless_(false) {} | |
34 ~NativeViewportAppDelegate() override {} | |
35 | |
36 private: | |
37 // mojo::ApplicationDelegate implementation. | |
38 void Initialize(mojo::ApplicationImpl* application) override { | |
39 application_ = application; | |
40 tracing_.Initialize(application); | |
41 | |
42 // Apply the switch for kTouchEvents to CommandLine (if set). This allows | |
43 // redirecting the mouse to a touch device on X for testing. | |
44 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
45 const std::string touch_event_string("--" + | |
46 std::string(switches::kTouchDevices)); | |
47 auto touch_iter = std::find(application->args().begin(), | |
48 application->args().end(), touch_event_string); | |
49 if (touch_iter != application->args().end() && | |
50 ++touch_iter != application->args().end()) { | |
51 command_line->AppendSwitchASCII(touch_event_string, *touch_iter); | |
52 } | |
53 | |
54 if (application->HasArg(mojo::kUseTestConfig)) | |
55 gfx::GLSurface::InitializeOneOffForTests(); | |
56 else if (application->HasArg(mojo::kUseOSMesa)) | |
57 gfx::GLSurface::InitializeOneOff(gfx::kGLImplementationOSMesaGL); | |
58 else | |
59 gfx::GLSurface::InitializeOneOff(); | |
60 | |
61 is_headless_ = application->HasArg(mojo::kUseHeadlessConfig); | |
62 } | |
63 | |
64 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | |
65 connection->AddService<NativeViewport>(this); | |
66 connection->AddService<Gpu>(this); | |
67 return true; | |
68 } | |
69 | |
70 // mojo::InterfaceFactory<NativeViewport> implementation. | |
71 void Create(ApplicationConnection* connection, | |
72 mojo::InterfaceRequest<NativeViewport> request) override { | |
73 if (!gpu_state_.get()) | |
74 gpu_state_ = new gles2::GpuState; | |
75 new NativeViewportImpl(application_, is_headless_, gpu_state_, | |
76 request.Pass()); | |
77 } | |
78 | |
79 // mojo::InterfaceFactory<Gpu> implementation. | |
80 void Create(ApplicationConnection* connection, | |
81 mojo::InterfaceRequest<Gpu> request) override { | |
82 if (!gpu_state_.get()) | |
83 gpu_state_ = new gles2::GpuState; | |
84 new gles2::GpuImpl(request.Pass(), gpu_state_); | |
85 } | |
86 | |
87 mojo::ApplicationImpl* application_; | |
88 scoped_refptr<gles2::GpuState> gpu_state_; | |
89 bool is_headless_; | |
90 mojo::TracingImpl tracing_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); | |
93 }; | |
94 } | |
95 | 10 |
96 MojoResult MojoMain(MojoHandle application_request) { | 11 MojoResult MojoMain(MojoHandle application_request) { |
| 12 #if defined(USE_OZONE) |
| 13 mojo::ApplicationRunnerChromium runner( |
| 14 new native_viewport::NativeViewportOzoneAppDelegate); |
| 15 #else |
97 mojo::ApplicationRunnerChromium runner( | 16 mojo::ApplicationRunnerChromium runner( |
98 new native_viewport::NativeViewportAppDelegate); | 17 new native_viewport::NativeViewportAppDelegate); |
| 18 #endif |
99 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); | 19 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); |
100 return runner.Run(application_request); | 20 return runner.Run(application_request); |
101 } | 21 } |
OLD | NEW |