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/message_loop/message_loop.h" |
| 6 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 7 #include "mojo/application/application_runner_chromium.h" |
| 8 #include "mojo/public/c/system/main.h" |
| 9 #include "mojo/public/cpp/application/application_connection.h" |
| 10 #include "mojo/public/cpp/application/application_delegate.h" |
| 11 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 12 #include "mojo/services/native_viewport/gpu_impl.h" |
| 13 #include "mojo/services/native_viewport/native_viewport_impl.h" |
| 14 #include "ui/gl/gl_share_group.h" |
| 15 #include "ui/gl/gl_surface.h" |
| 16 |
| 17 namespace mojo { |
| 18 |
| 19 class NativeViewportAppDelegate |
| 20 : public ApplicationDelegate, |
| 21 public InterfaceFactory<NativeViewport>, |
| 22 public InterfaceFactory<Gpu>, |
| 23 public InterfaceFactory<NativeViewportConfig> { |
| 24 public: |
| 25 NativeViewportAppDelegate() |
| 26 : share_group_(new gfx::GLShareGroup), |
| 27 mailbox_manager_(new gpu::gles2::MailboxManager), |
| 28 is_test_(false), |
| 29 is_initialized_(false) {} |
| 30 virtual ~NativeViewportAppDelegate() {} |
| 31 |
| 32 private: |
| 33 class NativeViewportConfigImpl : public InterfaceImpl<NativeViewportConfig> { |
| 34 public: |
| 35 NativeViewportConfigImpl(NativeViewportAppDelegate* app_delegate) |
| 36 : app_delegate_(app_delegate) {} |
| 37 |
| 38 virtual void UseTestConfig( |
| 39 const mojo::Callback<void()>& callback) OVERRIDE { |
| 40 app_delegate_->is_test_ = true; |
| 41 callback.Run(); |
| 42 } |
| 43 |
| 44 private: |
| 45 NativeViewportAppDelegate* app_delegate_; |
| 46 }; |
| 47 |
| 48 // ApplicationDelegate implementation. |
| 49 virtual void Initialize(ApplicationImpl* application) OVERRIDE { |
| 50 app_ = application; |
| 51 } |
| 52 |
| 53 virtual bool ConfigureIncomingConnection( |
| 54 mojo::ApplicationConnection* connection) OVERRIDE { |
| 55 connection->AddService<NativeViewport>(this); |
| 56 connection->AddService<Gpu>(this); |
| 57 connection->AddService<NativeViewportConfig>(this); |
| 58 return true; |
| 59 } |
| 60 |
| 61 // InterfaceFactory<NativeViewport> implementation. |
| 62 virtual void Create(ApplicationConnection* connection, |
| 63 InterfaceRequest<NativeViewport> request) OVERRIDE { |
| 64 #if !defined(COMPONENT_BUILD) |
| 65 if (!is_initialized_) { |
| 66 if (is_test_) |
| 67 gfx::GLSurface::InitializeOneOffForTests(); |
| 68 else |
| 69 gfx::GLSurface::InitializeOneOff(); |
| 70 is_initialized_ = true; |
| 71 } |
| 72 #endif |
| 73 BindToRequest(new NativeViewportImpl(app_), &request); |
| 74 } |
| 75 |
| 76 // InterfaceFactory<Gpu> implementation. |
| 77 virtual void Create(ApplicationConnection* connection, |
| 78 InterfaceRequest<Gpu> request) OVERRIDE { |
| 79 BindToRequest(new GpuImpl(share_group_.get(), mailbox_manager_.get()), |
| 80 &request); |
| 81 } |
| 82 |
| 83 // InterfaceFactory<NVTestConfig> implementation. |
| 84 virtual void Create(ApplicationConnection* connection, |
| 85 InterfaceRequest<NativeViewportConfig> request) OVERRIDE { |
| 86 BindToRequest(new NativeViewportConfigImpl(this), &request); |
| 87 } |
| 88 |
| 89 ApplicationImpl* app_; |
| 90 scoped_refptr<gfx::GLShareGroup> share_group_; |
| 91 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
| 92 bool is_test_; |
| 93 bool is_initialized_; |
| 94 DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); |
| 95 }; |
| 96 } |
| 97 |
| 98 MojoResult MojoMain(MojoHandle shell_handle) { |
| 99 mojo::ApplicationRunnerChromium runner(new mojo::NativeViewportAppDelegate); |
| 100 runner.set_message_loop_type(base::MessageLoop::TYPE_UI); |
| 101 return runner.Run(shell_handle); |
| 102 } |
OLD | NEW |