OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <algorithm> |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 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/gles2/gpu_impl.h" |
| 18 #include "mojo/services/native_viewport/native_viewport_impl.h" |
| 19 #include "third_party/mojo_services/src/native_viewport/public/cpp/args.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 tracing_.Initialize(application); |
| 40 |
| 41 #if defined(OS_LINUX) |
| 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(), |
| 49 touch_event_string); |
| 50 if (touch_iter != application->args().end() && |
| 51 ++touch_iter != application->args().end()) { |
| 52 command_line->AppendSwitchASCII(touch_event_string, *touch_iter); |
| 53 } |
| 54 #endif |
| 55 |
| 56 if (application->HasArg(mojo::kUseTestConfig)) |
| 57 gfx::GLSurface::InitializeOneOffForTests(); |
| 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(is_headless_, gpu_state_, request.Pass()); |
| 76 } |
| 77 |
| 78 // mojo::InterfaceFactory<Gpu> implementation. |
| 79 void Create(ApplicationConnection* connection, |
| 80 mojo::InterfaceRequest<Gpu> request) override { |
| 81 if (!gpu_state_.get()) |
| 82 gpu_state_ = new gles2::GpuState; |
| 83 new gles2::GpuImpl(request.Pass(), gpu_state_); |
| 84 } |
| 85 |
| 86 scoped_refptr<gles2::GpuState> gpu_state_; |
| 87 bool is_headless_; |
| 88 mojo::TracingImpl tracing_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); |
| 91 }; |
| 92 } |
| 93 |
| 94 MojoResult MojoMain(MojoHandle shell_handle) { |
| 95 mojo::ApplicationRunnerChromium runner( |
| 96 new native_viewport::NativeViewportAppDelegate); |
| 97 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); |
| 98 return runner.Run(shell_handle); |
| 99 } |
OLD | NEW |