Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: mojo/services/native_viewport/main.cc

Issue 606883002: Add a headless configuration to Mojo's native viewport service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "gpu/command_buffer/service/mailbox_manager.h" 6 #include "gpu/command_buffer/service/mailbox_manager.h"
7 #include "mojo/application/application_runner_chromium.h" 7 #include "mojo/application/application_runner_chromium.h"
8 #include "mojo/public/c/system/main.h" 8 #include "mojo/public/c/system/main.h"
9 #include "mojo/public/cpp/application/application_connection.h" 9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/application_delegate.h" 10 #include "mojo/public/cpp/application/application_delegate.h"
11 #include "mojo/public/cpp/application/interface_factory_impl.h" 11 #include "mojo/public/cpp/application/interface_factory_impl.h"
12 #include "mojo/services/native_viewport/gpu_impl.h" 12 #include "mojo/services/native_viewport/gpu_impl.h"
13 #include "mojo/services/native_viewport/native_viewport_impl.h" 13 #include "mojo/services/native_viewport/native_viewport_impl.h"
14 #include "ui/gl/gl_share_group.h" 14 #include "ui/gl/gl_share_group.h"
15 #include "ui/gl/gl_surface.h" 15 #include "ui/gl/gl_surface.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 18
19 class NativeViewportAppDelegate 19 class NativeViewportAppDelegate
20 : public ApplicationDelegate, 20 : public ApplicationDelegate,
21 public InterfaceFactory<NativeViewport>, 21 public InterfaceFactory<NativeViewport>,
22 public InterfaceFactory<Gpu>, 22 public InterfaceFactory<Gpu>,
23 public InterfaceFactory<NativeViewportConfig> { 23 public InterfaceFactory<NativeViewportConfig> {
24 public: 24 public:
25 NativeViewportAppDelegate() 25 NativeViewportAppDelegate()
26 : share_group_(new gfx::GLShareGroup), 26 : share_group_(new gfx::GLShareGroup),
27 mailbox_manager_(new gpu::gles2::MailboxManager), 27 mailbox_manager_(new gpu::gles2::MailboxManager),
28 is_test_(false), 28 is_test_(false),
29 is_headless_(false),
29 is_initialized_(false) {} 30 is_initialized_(false) {}
30 virtual ~NativeViewportAppDelegate() {} 31 virtual ~NativeViewportAppDelegate() {}
31 32
32 private: 33 private:
33 class NativeViewportConfigImpl : public InterfaceImpl<NativeViewportConfig> { 34 class NativeViewportConfigImpl : public InterfaceImpl<NativeViewportConfig> {
34 public: 35 public:
35 NativeViewportConfigImpl(NativeViewportAppDelegate* app_delegate) 36 NativeViewportConfigImpl(NativeViewportAppDelegate* app_delegate)
36 : app_delegate_(app_delegate) {} 37 : app_delegate_(app_delegate) {}
37 38
38 virtual void UseTestConfig( 39 virtual void UseTestConfig(
39 const mojo::Callback<void()>& callback) OVERRIDE { 40 const mojo::Callback<void()>& callback) OVERRIDE {
40 app_delegate_->is_test_ = true; 41 app_delegate_->is_test_ = true;
41 callback.Run(); 42 callback.Run();
42 } 43 }
43 44
45 virtual void UseHeadlessConfig(
46 const mojo::Callback<void()>& callback) OVERRIDE {
jamesr 2014/09/25 22:18:14 this code is in namespace mojo, no need to specify
47 app_delegate_->is_headless_ = true;
48 callback.Run();
49 }
50
44 private: 51 private:
45 NativeViewportAppDelegate* app_delegate_; 52 NativeViewportAppDelegate* app_delegate_;
46 }; 53 };
47 54
48 // ApplicationDelegate implementation. 55 // ApplicationDelegate implementation.
49 virtual void Initialize(ApplicationImpl* application) OVERRIDE { 56 virtual void Initialize(ApplicationImpl* application) OVERRIDE {
50 app_ = application; 57 app_ = application;
51 } 58 }
52 59
53 virtual bool ConfigureIncomingConnection( 60 virtual bool ConfigureIncomingConnection(
54 mojo::ApplicationConnection* connection) OVERRIDE { 61 mojo::ApplicationConnection* connection) OVERRIDE {
55 connection->AddService<NativeViewport>(this); 62 connection->AddService<NativeViewport>(this);
56 connection->AddService<Gpu>(this); 63 connection->AddService<Gpu>(this);
57 connection->AddService<NativeViewportConfig>(this); 64 connection->AddService<NativeViewportConfig>(this);
58 return true; 65 return true;
59 } 66 }
60 67
61 // InterfaceFactory<NativeViewport> implementation. 68 // InterfaceFactory<NativeViewport> implementation.
62 virtual void Create(ApplicationConnection* connection, 69 virtual void Create(ApplicationConnection* connection,
63 InterfaceRequest<NativeViewport> request) OVERRIDE { 70 InterfaceRequest<NativeViewport> request) OVERRIDE {
64 #if !defined(COMPONENT_BUILD) 71 #if !defined(COMPONENT_BUILD)
65 if (!is_initialized_) { 72 if (!is_initialized_) {
66 if (is_test_) 73 if (is_test_)
67 gfx::GLSurface::InitializeOneOffForTests(); 74 gfx::GLSurface::InitializeOneOffForTests();
68 else 75 else
69 gfx::GLSurface::InitializeOneOff(); 76 gfx::GLSurface::InitializeOneOff();
70 is_initialized_ = true; 77 is_initialized_ = true;
71 } 78 }
72 #endif 79 #endif
73 BindToRequest(new NativeViewportImpl(app_), &request); 80 BindToRequest(new NativeViewportImpl(app_, is_headless_), &request);
74 } 81 }
75 82
76 // InterfaceFactory<Gpu> implementation. 83 // InterfaceFactory<Gpu> implementation.
77 virtual void Create(ApplicationConnection* connection, 84 virtual void Create(ApplicationConnection* connection,
78 InterfaceRequest<Gpu> request) OVERRIDE { 85 InterfaceRequest<Gpu> request) OVERRIDE {
79 BindToRequest(new GpuImpl(share_group_.get(), mailbox_manager_.get()), 86 BindToRequest(new GpuImpl(share_group_.get(), mailbox_manager_.get()),
80 &request); 87 &request);
81 } 88 }
82 89
83 // InterfaceFactory<NVTestConfig> implementation. 90 // InterfaceFactory<NVTestConfig> implementation.
84 virtual void Create(ApplicationConnection* connection, 91 virtual void Create(ApplicationConnection* connection,
85 InterfaceRequest<NativeViewportConfig> request) OVERRIDE { 92 InterfaceRequest<NativeViewportConfig> request) OVERRIDE {
86 BindToRequest(new NativeViewportConfigImpl(this), &request); 93 BindToRequest(new NativeViewportConfigImpl(this), &request);
87 } 94 }
88 95
89 ApplicationImpl* app_; 96 ApplicationImpl* app_;
90 scoped_refptr<gfx::GLShareGroup> share_group_; 97 scoped_refptr<gfx::GLShareGroup> share_group_;
91 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; 98 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
92 bool is_test_; 99 bool is_test_;
100 bool is_headless_;
93 bool is_initialized_; 101 bool is_initialized_;
94 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); 102 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate);
95 }; 103 };
96 } 104 }
97 105
98 MojoResult MojoMain(MojoHandle shell_handle) { 106 MojoResult MojoMain(MojoHandle shell_handle) {
99 mojo::ApplicationRunnerChromium runner(new mojo::NativeViewportAppDelegate); 107 mojo::ApplicationRunnerChromium runner(new mojo::NativeViewportAppDelegate);
100 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); 108 runner.set_message_loop_type(base::MessageLoop::TYPE_UI);
101 return runner.Run(shell_handle); 109 return runner.Run(shell_handle);
102 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698