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 #include <algorithm> |
6 | 6 |
7 #include "base/bind.h" | |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "mojo/application/application_runner_chromium.h" | 11 #include "mojo/application/application_runner_chromium.h" |
11 #include "mojo/common/tracing_impl.h" | 12 #include "mojo/common/tracing_impl.h" |
12 #include "mojo/public/c/system/main.h" | 13 #include "mojo/public/c/system/main.h" |
13 #include "mojo/public/cpp/application/application_connection.h" | 14 #include "mojo/public/cpp/application/application_connection.h" |
14 #include "mojo/public/cpp/application/application_delegate.h" | 15 #include "mojo/public/cpp/application/application_delegate.h" |
15 #include "mojo/public/cpp/application/application_impl.h" | 16 #include "mojo/public/cpp/application/application_impl.h" |
16 #include "mojo/public/cpp/application/interface_factory_impl.h" | 17 #include "mojo/public/cpp/application/interface_factory_impl.h" |
17 #include "mojo/services/native_viewport/public/cpp/args.h" | 18 #include "mojo/services/native_viewport/public/cpp/args.h" |
18 #include "services/gles2/gpu_impl.h" | 19 #include "services/gles2/gpu_impl.h" |
19 #include "services/native_viewport/native_viewport_impl.h" | 20 #include "services/native_viewport/native_viewport_impl.h" |
20 #include "ui/events/event_switches.h" | 21 #include "ui/events/event_switches.h" |
21 #include "ui/gl/gl_surface.h" | 22 #include "ui/gl/gl_surface.h" |
22 | 23 |
24 #if defined(USE_OZONE) | |
25 #include "mojo/services/ozone_drm_gpu/public/interfaces/ozone_drm_gpu.mojom.h" //nogncheck | |
26 #include "mojo/services/ozone_drm_host/public/interfaces/ozone_drm_host.mojom.h" //nogncheck | |
27 #include "services/native_viewport/ozone/display_manager.h" //nogncheck | |
28 #include "services/native_viewport/ozone/ozone_drm_gpu_impl.h" //nogncheck | |
29 #include "services/native_viewport/ozone/ozone_drm_host_impl.h" //nogncheck | |
30 #include "ui/ozone/public/ozone_platform.h" //nogncheck | |
31 #endif | |
32 | |
23 using mojo::ApplicationConnection; | 33 using mojo::ApplicationConnection; |
24 using mojo::Gpu; | 34 using mojo::Gpu; |
25 using mojo::NativeViewport; | 35 using mojo::NativeViewport; |
26 | 36 |
37 #if defined(USE_OZONE) | |
38 using mojo::OzoneDrmGpu; | |
39 using mojo::OzoneDrmHost; | |
40 #endif | |
41 | |
27 namespace native_viewport { | 42 namespace native_viewport { |
28 | 43 |
29 class NativeViewportAppDelegate : public mojo::ApplicationDelegate, | 44 class NativeViewportAppDelegate : public mojo::ApplicationDelegate, |
30 public mojo::InterfaceFactory<NativeViewport>, | 45 public mojo::InterfaceFactory<NativeViewport>, |
31 public mojo::InterfaceFactory<Gpu> { | 46 public mojo::InterfaceFactory<Gpu> { |
32 public: | 47 public: |
33 NativeViewportAppDelegate() : is_headless_(false) {} | 48 NativeViewportAppDelegate() : is_headless_(false) {} |
34 ~NativeViewportAppDelegate() override {} | 49 ~NativeViewportAppDelegate() override {} |
35 | 50 |
36 private: | |
37 // mojo::ApplicationDelegate implementation. | 51 // mojo::ApplicationDelegate implementation. |
38 void Initialize(mojo::ApplicationImpl* application) override { | 52 void Initialize(mojo::ApplicationImpl* application) override { |
39 application_ = application; | 53 application_ = application; |
54 | |
40 tracing_.Initialize(application); | 55 tracing_.Initialize(application); |
41 | 56 |
42 // Apply the switch for kTouchEvents to CommandLine (if set). This allows | 57 // Apply the switch for kTouchEvents to CommandLine (if set). This allows |
43 // redirecting the mouse to a touch device on X for testing. | 58 // redirecting the mouse to a touch device on X for testing. |
44 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 59 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
45 const std::string touch_event_string("--" + | 60 const std::string touch_event_string("--" + |
46 std::string(switches::kTouchDevices)); | 61 std::string(switches::kTouchDevices)); |
47 auto touch_iter = std::find(application->args().begin(), | 62 auto touch_iter = std::find(application->args().begin(), |
48 application->args().end(), touch_event_string); | 63 application->args().end(), touch_event_string); |
49 if (touch_iter != application->args().end() && | 64 if (touch_iter != application->args().end() && |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 new gles2::GpuImpl(request.Pass(), gpu_state_); | 99 new gles2::GpuImpl(request.Pass(), gpu_state_); |
85 } | 100 } |
86 | 101 |
87 mojo::ApplicationImpl* application_; | 102 mojo::ApplicationImpl* application_; |
88 scoped_refptr<gles2::GpuState> gpu_state_; | 103 scoped_refptr<gles2::GpuState> gpu_state_; |
89 bool is_headless_; | 104 bool is_headless_; |
90 mojo::TracingImpl tracing_; | 105 mojo::TracingImpl tracing_; |
91 | 106 |
92 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); | 107 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); |
93 }; | 108 }; |
94 } | 109 |
110 #if defined(USE_OZONE) | |
jamesr
2015/08/25 00:30:28
can this stuff go somewhere other than main.cc? y
cdotstout
2015/08/27 19:10:21
Done.
| |
111 class NativeViewportOzoneDrmAppDelegate | |
112 : public NativeViewportAppDelegate, | |
113 public mojo::InterfaceFactory<OzoneDrmHost>, | |
114 public mojo::InterfaceFactory<OzoneDrmGpu> { | |
115 public: | |
116 using NativeViewportAppDelegate::Create; | |
117 | |
118 void Initialize(mojo::ApplicationImpl* application) override { | |
119 NativeViewportAppDelegate::Initialize(application); | |
120 application->ConnectToService("mojo:native_viewport_service", | |
121 &ozone_drm_gpu_); | |
122 application->ConnectToService("mojo:native_viewport_service", | |
123 &ozone_drm_host_); | |
124 } | |
125 | |
126 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | |
127 if (!NativeViewportAppDelegate::ConfigureIncomingConnection(connection)) | |
128 return false; | |
129 connection->AddService<OzoneDrmGpu>(this); | |
130 connection->AddService<OzoneDrmHost>(this); | |
131 return true; | |
132 } | |
133 | |
134 // mojo::InterfaceFactory<OzoneDrmGpu> implementation. | |
135 void Create(ApplicationConnection* connection, | |
136 mojo::InterfaceRequest<OzoneDrmGpu> request) override { | |
137 new OzoneDrmGpuImpl(request.Pass(), ozone_drm_host_); | |
138 } | |
139 | |
140 // mojo::InterfaceFactory<OzoneDrmHost> implementation. | |
141 void Create(ApplicationConnection* connection, | |
142 mojo::InterfaceRequest<OzoneDrmHost> request) override { | |
143 ui::OzonePlatform::InitializeForUI(); | |
144 new OzoneDrmHostImpl(request.Pass(), ozone_drm_gpu_); | |
145 | |
146 display_manager_.reset(new DisplayManager()); | |
147 } | |
148 | |
149 private: | |
150 std::unique_ptr<DisplayManager> display_manager_; | |
151 mojo::OzoneDrmHostPtr ozone_drm_host_; | |
152 mojo::OzoneDrmGpuPtr ozone_drm_gpu_; | |
153 }; | |
154 | |
155 #endif | |
156 | |
157 } // namespace | |
95 | 158 |
96 MojoResult MojoMain(MojoHandle application_request) { | 159 MojoResult MojoMain(MojoHandle application_request) { |
160 #if defined(USE_OZONE) | |
161 mojo::ApplicationRunnerChromium runner( | |
162 new native_viewport::NativeViewportOzoneDrmAppDelegate); | |
163 #else | |
97 mojo::ApplicationRunnerChromium runner( | 164 mojo::ApplicationRunnerChromium runner( |
98 new native_viewport::NativeViewportAppDelegate); | 165 new native_viewport::NativeViewportAppDelegate); |
166 #endif | |
99 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); | 167 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); |
100 return runner.Run(application_request); | 168 return runner.Run(application_request); |
101 } | 169 } |
OLD | NEW |