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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 class NativeViewportAppDelegate : public mojo::ApplicationDelegate, | 29 class NativeViewportAppDelegate : public mojo::ApplicationDelegate, |
30 public mojo::InterfaceFactory<NativeViewport>, | 30 public mojo::InterfaceFactory<NativeViewport>, |
31 public mojo::InterfaceFactory<Gpu> { | 31 public mojo::InterfaceFactory<Gpu> { |
32 public: | 32 public: |
33 NativeViewportAppDelegate() : is_headless_(false) {} | 33 NativeViewportAppDelegate() : is_headless_(false) {} |
34 ~NativeViewportAppDelegate() override {} | 34 ~NativeViewportAppDelegate() override {} |
35 | 35 |
36 private: | 36 private: |
37 // mojo::ApplicationDelegate implementation. | 37 // mojo::ApplicationDelegate implementation. |
38 void Initialize(mojo::ApplicationImpl* application) override { | 38 void Initialize(mojo::ApplicationImpl* application) override { |
| 39 application_ = application; |
39 tracing_.Initialize(application); | 40 tracing_.Initialize(application); |
40 | 41 |
41 // Apply the switch for kTouchEvents to CommandLine (if set). This allows | 42 // Apply the switch for kTouchEvents to CommandLine (if set). This allows |
42 // redirecting the mouse to a touch device on X for testing. | 43 // redirecting the mouse to a touch device on X for testing. |
43 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 44 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
44 const std::string touch_event_string("--" + | 45 const std::string touch_event_string("--" + |
45 std::string(switches::kTouchDevices)); | 46 std::string(switches::kTouchDevices)); |
46 auto touch_iter = std::find(application->args().begin(), | 47 auto touch_iter = std::find(application->args().begin(), |
47 application->args().end(), | 48 application->args().end(), touch_event_string); |
48 touch_event_string); | |
49 if (touch_iter != application->args().end() && | 49 if (touch_iter != application->args().end() && |
50 ++touch_iter != application->args().end()) { | 50 ++touch_iter != application->args().end()) { |
51 command_line->AppendSwitchASCII(touch_event_string, *touch_iter); | 51 command_line->AppendSwitchASCII(touch_event_string, *touch_iter); |
52 } | 52 } |
53 | 53 |
54 if (application->HasArg(mojo::kUseTestConfig)) | 54 if (application->HasArg(mojo::kUseTestConfig)) |
55 gfx::GLSurface::InitializeOneOffForTests(); | 55 gfx::GLSurface::InitializeOneOffForTests(); |
56 else if (application->HasArg(mojo::kUseOSMesa)) | 56 else if (application->HasArg(mojo::kUseOSMesa)) |
57 gfx::GLSurface::InitializeOneOff(gfx::kGLImplementationOSMesaGL); | 57 gfx::GLSurface::InitializeOneOff(gfx::kGLImplementationOSMesaGL); |
58 else | 58 else |
59 gfx::GLSurface::InitializeOneOff(); | 59 gfx::GLSurface::InitializeOneOff(); |
60 | 60 |
61 is_headless_ = application->HasArg(mojo::kUseHeadlessConfig); | 61 is_headless_ = application->HasArg(mojo::kUseHeadlessConfig); |
62 } | 62 } |
63 | 63 |
64 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 64 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
65 connection->AddService<NativeViewport>(this); | 65 connection->AddService<NativeViewport>(this); |
66 connection->AddService<Gpu>(this); | 66 connection->AddService<Gpu>(this); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 // mojo::InterfaceFactory<NativeViewport> implementation. | 70 // mojo::InterfaceFactory<NativeViewport> implementation. |
71 void Create(ApplicationConnection* connection, | 71 void Create(ApplicationConnection* connection, |
72 mojo::InterfaceRequest<NativeViewport> request) override { | 72 mojo::InterfaceRequest<NativeViewport> request) override { |
73 if (!gpu_state_.get()) | 73 if (!gpu_state_.get()) |
74 gpu_state_ = new gles2::GpuState; | 74 gpu_state_ = new gles2::GpuState; |
75 new NativeViewportImpl(is_headless_, gpu_state_, request.Pass()); | 75 new NativeViewportImpl(application_, is_headless_, gpu_state_, |
| 76 request.Pass()); |
76 } | 77 } |
77 | 78 |
78 // mojo::InterfaceFactory<Gpu> implementation. | 79 // mojo::InterfaceFactory<Gpu> implementation. |
79 void Create(ApplicationConnection* connection, | 80 void Create(ApplicationConnection* connection, |
80 mojo::InterfaceRequest<Gpu> request) override { | 81 mojo::InterfaceRequest<Gpu> request) override { |
81 if (!gpu_state_.get()) | 82 if (!gpu_state_.get()) |
82 gpu_state_ = new gles2::GpuState; | 83 gpu_state_ = new gles2::GpuState; |
83 new gles2::GpuImpl(request.Pass(), gpu_state_); | 84 new gles2::GpuImpl(request.Pass(), gpu_state_); |
84 } | 85 } |
85 | 86 |
| 87 mojo::ApplicationImpl* application_; |
86 scoped_refptr<gles2::GpuState> gpu_state_; | 88 scoped_refptr<gles2::GpuState> gpu_state_; |
87 bool is_headless_; | 89 bool is_headless_; |
88 mojo::TracingImpl tracing_; | 90 mojo::TracingImpl tracing_; |
89 | 91 |
90 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); | 92 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); |
91 }; | 93 }; |
92 } | 94 } |
93 | 95 |
94 MojoResult MojoMain(MojoHandle application_request) { | 96 MojoResult MojoMain(MojoHandle application_request) { |
95 mojo::ApplicationRunnerChromium runner( | 97 mojo::ApplicationRunnerChromium runner( |
96 new native_viewport::NativeViewportAppDelegate); | 98 new native_viewport::NativeViewportAppDelegate); |
97 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); | 99 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); |
98 return runner.Run(application_request); | 100 return runner.Run(application_request); |
99 } | 101 } |
OLD | NEW |