1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Copyright 2014 The Chromium Authors. All rights reserved. 2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Use of this source code is governed by a BSD-style license that can be 3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// found in the LICENSE file. 4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "base/threading/platform_thread.h" 6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "mojo/application/application_runner_chromium.h" 7ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "mojo/examples/surfaces_app/child_gl_impl.h" 8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "mojo/public/c/system/main.h" 9ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "mojo/public/cpp/application/application_connection.h" 10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "mojo/public/cpp/application/application_delegate.h" 11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "mojo/public/cpp/application/application_impl.h" 12ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "mojo/public/cpp/bindings/string.h" 13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "mojo/services/public/interfaces/gpu/gpu.mojom.h" 14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovnamespace mojo { 16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovnamespace examples { 17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass ChildGLApp : public ApplicationDelegate, public InterfaceFactory<Child> { 19ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov public: 20ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov ChildGLApp() {} 21ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov virtual ~ChildGLApp() {} 22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov virtual void Initialize(ApplicationImpl* app) OVERRIDE { 24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov surfaces_service_connection_ = 25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov app->ConnectToApplication("mojo:mojo_surfaces_service"); 26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov // TODO(jamesr): Should be mojo:mojo_gpu_service 27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); 28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov } 29ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 30ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov // ApplicationDelegate implementation. 31ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov virtual bool ConfigureIncomingConnection( 32ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov ApplicationConnection* connection) OVERRIDE { 33ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov connection->AddService(this); 34ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov return true; 35ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov } 36ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 37ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov // InterfaceFactory<Child> implementation. 38ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov virtual void Create(ApplicationConnection* connection, 39ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov InterfaceRequest<Child> request) OVERRIDE { 40ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov CommandBufferPtr command_buffer; 41ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov gpu_service_->CreateOffscreenGLES2Context(Get(&command_buffer)); 42ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov BindToRequest( 43ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov new ChildGLImpl(surfaces_service_connection_, command_buffer.Pass()), 44ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov &request); 45ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov } 46ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 47ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov private: 48ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov ApplicationConnection* surfaces_service_connection_; 49ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov GpuPtr gpu_service_; 50ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 51ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov DISALLOW_COPY_AND_ASSIGN(ChildGLApp); 52ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov}; 53ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 54ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov} // namespace examples 55ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov} // namespace mojo 56ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov 57ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovMojoResult MojoMain(MojoHandle shell_handle) { 58ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov mojo::ApplicationRunnerChromium runner(new mojo::examples::ChildGLApp); 59ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov return runner.Run(shell_handle); 60ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov} 61ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov