| 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 "base/command_line.h" | |
| 6 #include "base/macros.h" | |
| 7 #include "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 8 #include "components/gles2/gpu_impl.h" | 6 #include "components/native_viewport/native_viewport_application_delegate.h" |
| 9 #include "components/native_viewport/native_viewport_impl.h" | |
| 10 #include "components/native_viewport/public/cpp/args.h" | |
| 11 #include "mojo/application/application_runner_chromium.h" | 7 #include "mojo/application/application_runner_chromium.h" |
| 12 #include "mojo/application/public/cpp/application_connection.h" | |
| 13 #include "mojo/application/public/cpp/application_delegate.h" | |
| 14 #include "mojo/application/public/cpp/application_impl.h" | |
| 15 #include "mojo/application/public/cpp/interface_factory_impl.h" | |
| 16 #include "mojo/common/tracing_impl.h" | |
| 17 #include "third_party/mojo/src/mojo/public/c/system/main.h" | 8 #include "third_party/mojo/src/mojo/public/c/system/main.h" |
| 18 #include "ui/events/event_switches.h" | |
| 19 #include "ui/gl/gl_surface.h" | |
| 20 | |
| 21 using mojo::ApplicationConnection; | |
| 22 using mojo::Gpu; | |
| 23 using mojo::NativeViewport; | |
| 24 | |
| 25 namespace native_viewport { | |
| 26 | |
| 27 class NativeViewportAppDelegate : public mojo::ApplicationDelegate, | |
| 28 public mojo::InterfaceFactory<NativeViewport>, | |
| 29 public mojo::InterfaceFactory<Gpu> { | |
| 30 public: | |
| 31 NativeViewportAppDelegate() : is_headless_(false) {} | |
| 32 ~NativeViewportAppDelegate() override {} | |
| 33 | |
| 34 private: | |
| 35 // mojo::ApplicationDelegate implementation. | |
| 36 void Initialize(mojo::ApplicationImpl* application) override { | |
| 37 tracing_.Initialize(application); | |
| 38 | |
| 39 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 40 is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig); | |
| 41 if (!is_headless_) { | |
| 42 if (command_line->HasSwitch(mojo::kUseTestConfig)) | |
| 43 gfx::GLSurface::InitializeOneOffForTests(); | |
| 44 else | |
| 45 gfx::GLSurface::InitializeOneOff(); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | |
| 50 connection->AddService<NativeViewport>(this); | |
| 51 connection->AddService<Gpu>(this); | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 // mojo::InterfaceFactory<NativeViewport> implementation. | |
| 56 void Create(ApplicationConnection* connection, | |
| 57 mojo::InterfaceRequest<NativeViewport> request) override { | |
| 58 if (!gpu_state_.get()) | |
| 59 gpu_state_ = new gles2::GpuState; | |
| 60 new NativeViewportImpl(is_headless_, gpu_state_, request.Pass()); | |
| 61 } | |
| 62 | |
| 63 // mojo::InterfaceFactory<Gpu> implementation. | |
| 64 void Create(ApplicationConnection* connection, | |
| 65 mojo::InterfaceRequest<Gpu> request) override { | |
| 66 if (!gpu_state_.get()) | |
| 67 gpu_state_ = new gles2::GpuState; | |
| 68 new gles2::GpuImpl(request.Pass(), gpu_state_); | |
| 69 } | |
| 70 | |
| 71 scoped_refptr<gles2::GpuState> gpu_state_; | |
| 72 bool is_headless_; | |
| 73 mojo::TracingImpl tracing_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); | |
| 76 }; | |
| 77 } | |
| 78 | 9 |
| 79 MojoResult MojoMain(MojoHandle shell_handle) { | 10 MojoResult MojoMain(MojoHandle shell_handle) { |
| 80 mojo::ApplicationRunnerChromium runner( | 11 mojo::ApplicationRunnerChromium runner( |
| 81 new native_viewport::NativeViewportAppDelegate); | 12 new native_viewport::NativeViewportApplicationDelegate); |
| 82 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); | 13 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); |
| 83 return runner.Run(shell_handle); | 14 return runner.Run(shell_handle); |
| 84 } | 15 } |
| OLD | NEW |