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

Unified Diff: mojo/services/native_viewport/main.cc

Issue 477923004: Create native_viewport_service, don't build it into mojo_shell unless Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try to get gn build working again Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/native_viewport/main.cc
diff --git a/mojo/services/native_viewport/main.cc b/mojo/services/native_viewport/main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fb150da28daed961b7aa3c6bec9f2196de998703
--- /dev/null
+++ b/mojo/services/native_viewport/main.cc
@@ -0,0 +1,102 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/message_loop/message_loop.h"
+#include "gpu/command_buffer/service/mailbox_manager.h"
+#include "mojo/application/application_runner_chromium.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/interface_factory_impl.h"
+#include "mojo/services/native_viewport/gpu_impl.h"
+#include "mojo/services/native_viewport/native_viewport_impl.h"
+#include "ui/gl/gl_share_group.h"
+#include "ui/gl/gl_surface.h"
+
+namespace mojo {
+
+class NativeViewportAppDelegate
+ : public ApplicationDelegate,
+ public InterfaceFactory<NativeViewport>,
+ public InterfaceFactory<Gpu>,
+ public InterfaceFactory<NativeViewportConfig> {
+ public:
+ NativeViewportAppDelegate()
+ : share_group_(new gfx::GLShareGroup),
+ mailbox_manager_(new gpu::gles2::MailboxManager),
+ is_test_(false),
+ is_initialized_(false) {}
+ virtual ~NativeViewportAppDelegate() {}
+
+ private:
+ class NativeViewportConfigImpl : public InterfaceImpl<NativeViewportConfig> {
+ public:
+ NativeViewportConfigImpl(NativeViewportAppDelegate* app_delegate)
+ : app_delegate_(app_delegate) {}
+
+ virtual void UseTestConfig(
+ const mojo::Callback<void()>& callback) OVERRIDE {
+ app_delegate_->is_test_ = true;
+ callback.Run();
+ }
+
+ private:
+ NativeViewportAppDelegate* app_delegate_;
+ };
+
+ // ApplicationDelegate implementation.
+ virtual void Initialize(ApplicationImpl* application) OVERRIDE {
+ app_ = application;
+ }
+
+ virtual bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) OVERRIDE {
+ connection->AddService<NativeViewport>(this);
+ connection->AddService<Gpu>(this);
+ connection->AddService<NativeViewportConfig>(this);
+ return true;
+ }
+
+ // InterfaceFactory<NativeViewport> implementation.
+ virtual void Create(ApplicationConnection* connection,
+ InterfaceRequest<NativeViewport> request) OVERRIDE {
+#if !defined(COMPONENT_BUILD)
+ if (!is_initialized_) {
+ if (is_test_)
+ gfx::GLSurface::InitializeOneOffForTests();
+ else
+ gfx::GLSurface::InitializeOneOff();
+ is_initialized_ = true;
+ }
+#endif
+ BindToRequest(new NativeViewportImpl(app_), &request);
+ }
+
+ // InterfaceFactory<Gpu> implementation.
+ virtual void Create(ApplicationConnection* connection,
+ InterfaceRequest<Gpu> request) OVERRIDE {
+ BindToRequest(new GpuImpl(share_group_.get(), mailbox_manager_.get()),
+ &request);
+ }
+
+ // InterfaceFactory<NVTestConfig> implementation.
+ virtual void Create(ApplicationConnection* connection,
+ InterfaceRequest<NativeViewportConfig> request) OVERRIDE {
+ BindToRequest(new NativeViewportConfigImpl(this), &request);
+ }
+
+ ApplicationImpl* app_;
+ scoped_refptr<gfx::GLShareGroup> share_group_;
+ scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
+ bool is_test_;
+ bool is_initialized_;
+ DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate);
+};
+}
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunnerChromium runner(new mojo::NativeViewportAppDelegate);
+ runner.set_message_loop_type(base::MessageLoop::TYPE_UI);
+ return runner.Run(shell_handle);
+}

Powered by Google App Engine
This is Rietveld 408576698