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 "base/macros.h" | |
6 #include "base/message_loop/message_loop.h" | |
7 #include "gpu/command_buffer/service/mailbox_manager_impl.h" | |
8 #include "mojo/application/application_runner_chromium.h" | |
9 #include "mojo/public/c/system/main.h" | |
10 #include "mojo/public/cpp/application/application_connection.h" | |
11 #include "mojo/public/cpp/application/application_delegate.h" | |
12 #include "mojo/public/cpp/application/application_impl.h" | |
13 #include "mojo/public/cpp/application/interface_factory_impl.h" | |
14 #include "mojo/services/native_viewport/gpu_impl.h" | |
15 #include "mojo/services/native_viewport/native_viewport_impl.h" | |
16 #include "mojo/services/public/cpp/native_viewport/args.h" | |
17 #include "ui/gl/gl_share_group.h" | |
18 #include "ui/gl/gl_surface.h" | |
19 | |
20 namespace mojo { | |
21 | |
22 class NativeViewportAppDelegate | |
23 : public ApplicationDelegate, | |
24 public InterfaceFactory<NativeViewport>, | |
25 public InterfaceFactory<Gpu> { | |
26 public: | |
27 NativeViewportAppDelegate() | |
28 : share_group_(new gfx::GLShareGroup), | |
29 mailbox_manager_(new gpu::gles2::MailboxManagerImpl), | |
30 is_headless_(false) {} | |
31 ~NativeViewportAppDelegate() override {} | |
32 | |
33 private: | |
34 bool HasArg(const std::string& arg) { | |
35 const auto& args = app_->args(); | |
36 return std::find(args.begin(), args.end(), arg) != args.end(); | |
37 } | |
38 | |
39 // ApplicationDelegate implementation. | |
40 void Initialize(ApplicationImpl* application) override { | |
41 app_ = application; | |
42 | |
43 #if !defined(COMPONENT_BUILD) | |
44 if (HasArg(kUseTestConfig)) | |
45 gfx::GLSurface::InitializeOneOffForTests(); | |
46 else | |
47 gfx::GLSurface::InitializeOneOff(); | |
48 #endif | |
49 is_headless_ = HasArg(kUseHeadlessConfig); | |
50 } | |
51 | |
52 bool ConfigureIncomingConnection( | |
53 mojo::ApplicationConnection* connection) override { | |
54 connection->AddService<NativeViewport>(this); | |
55 connection->AddService<Gpu>(this); | |
56 return true; | |
57 } | |
58 | |
59 // InterfaceFactory<NativeViewport> implementation. | |
60 void Create(ApplicationConnection* connection, | |
61 InterfaceRequest<NativeViewport> request) override { | |
62 BindToRequest(new NativeViewportImpl(app_, is_headless_), &request); | |
63 } | |
64 | |
65 // InterfaceFactory<Gpu> implementation. | |
66 void Create(ApplicationConnection* connection, | |
67 InterfaceRequest<Gpu> request) override { | |
68 BindToRequest(new GpuImpl(share_group_.get(), mailbox_manager_.get()), | |
69 &request); | |
70 } | |
71 | |
72 ApplicationImpl* app_; | |
73 scoped_refptr<gfx::GLShareGroup> share_group_; | |
74 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | |
75 bool is_headless_; | |
76 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); | |
77 }; | |
78 } | |
79 | |
80 MojoResult MojoMain(MojoHandle shell_handle) { | |
81 mojo::ApplicationRunnerChromium runner(new mojo::NativeViewportAppDelegate); | |
82 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); | |
83 return runner.Run(shell_handle); | |
84 } | |
OLD | NEW |