15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <stdio.h> 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string> 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "base/macros.h" 91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "mojo/application/application_runner_chromium.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "mojo/examples/compositor_app/compositor_host.h" 1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "mojo/public/c/system/main.h" 12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "mojo/public/cpp/application/application_delegate.h" 13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "mojo/public/cpp/application/application_impl.h" 14effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "mojo/public/cpp/system/core.h" 15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" 1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "mojo/services/public/interfaces/gpu/gpu.mojom.h" 17f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/rect.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace mojo { 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace examples { 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 23116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass SampleApp : public ApplicationDelegate, public NativeViewportClient { 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) SampleApp() {} 26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual ~SampleApp() {} 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void Initialize(ApplicationImpl* app) OVERRIDE { 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); 30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) viewport_.set_client(this); 311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci viewport_->Create(Size::From(gfx::Size(800, 600))); 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) viewport_->Show(); 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // TODO(jamesr): Should be mojo:mojo_gpu_service 3503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE { 3903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) CommandBufferPtr cb; 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // TODO(jamesr): Output to a surface instead. 4103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) gpu_service_->CreateOnscreenGLES2Context( 4203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) native_viewport_id, Size::From(gfx::Size(800, 600)), Get(&cb)); 4303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) host_.reset(new CompositorHost(cb.PassMessagePipe())); 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void OnDestroyed() OVERRIDE { base::MessageLoop::current()->Quit(); } 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void OnBoundsChanged(SizePtr bounds) OVERRIDE { 4903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) if (host_) 501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci host_->SetSize(bounds.To<gfx::Size>()); 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void OnEvent(EventPtr event, 54e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const mojo::Callback<void()>& callback) OVERRIDE { 55e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch callback.Run(); 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 590de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) NativeViewportPtr viewport_; 6003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) GpuPtr gpu_service_; 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<CompositorHost> host_; 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SampleApp); 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace examples 6603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)} // namespace mojo 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)MojoResult MojoMain(MojoHandle shell_handle) { 6903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) mojo::ApplicationRunnerChromium runner(new mojo::examples::SampleApp); 7003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return runner.Run(shell_handle); 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 72