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