Skip to content

Commit

Permalink
Change mojo demo apps to use Application.
Browse files Browse the repository at this point in the history
BUG=None
R=darin@chromium.org, ben

Review URL: https://codereview.chromium.org/162213002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251076 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
davemoore@chromium.org committed Feb 13, 2014
1 parent 58712c6 commit 06863b3
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 114 deletions.
20 changes: 6 additions & 14 deletions mojo/examples/aura_demo/aura_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "mojo/examples/aura_demo/demo_screen.h"
#include "mojo/examples/aura_demo/root_window_host_mojo.h"
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/gles2/gles2_cpp.h"
#include "mojo/public/shell/application.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
#include "mojom/native_viewport.h"
Expand Down Expand Up @@ -115,29 +115,23 @@ class DemoWindowTreeClient : public aura::client::WindowTreeClient {
DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient);
};

class AuraDemo : public ShellClient {
class AuraDemo : public Application {
public:
explicit AuraDemo(ScopedShellHandle shell_handle)
: shell_(shell_handle.Pass(), this) {
explicit AuraDemo(MojoHandle shell_handle) : Application(shell_handle) {
screen_.reset(DemoScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());

InterfacePipe<NativeViewport, AnyInterface> pipe;

mojo::AllocationScope scope;
shell_->Connect("mojo:mojo_native_viewport_service",
pipe.handle_to_peer.Pass());
shell()->Connect("mojo:mojo_native_viewport_service",
pipe.handle_to_peer.Pass());
root_window_host_.reset(new WindowTreeHostMojo(
pipe.handle_to_self.Pass(),
gfx::Rect(800, 600),
base::Bind(&AuraDemo::HostContextCreated, base::Unretained(this))));
}

virtual void AcceptConnection(const mojo::String& url,
ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
NOTREACHED() << "AuraDemo can't be connected to.";
}

private:
void HostContextCreated() {
aura::RootWindow::CreateParams params(
Expand Down Expand Up @@ -185,7 +179,6 @@ class AuraDemo : public ShellClient {
aura::Window* window2_;
aura::Window* window21_;

RemotePtr<Shell> shell_;
scoped_ptr<WindowTreeHostMojo> root_window_host_;
scoped_ptr<aura::RootWindow> root_window_;
};
Expand All @@ -204,8 +197,7 @@ extern "C" AURA_DEMO_EXPORT MojoResult CDECL MojoMain(
// MessageLoop is not of TYPE_UI. I think we need a way to build
// Aura that doesn't define platform-specific stuff.
aura::Env::CreateInstance();
mojo::examples::AuraDemo app(
mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass());
mojo::examples::AuraDemo app(shell_handle);
loop.Run();

return MOJO_RESULT_OK;
Expand Down
85 changes: 31 additions & 54 deletions mojo/examples/compositor_app/compositor_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/gles2/gles2_cpp.h"
#include "mojo/public/shell/application.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
#include "mojo/services/native_viewport/geometry_conversions.h"
Expand All @@ -30,67 +31,46 @@
namespace mojo {
namespace examples {

class SampleApp : public ShellClient {
class SampleApp : public Application, public NativeViewportClient {
public:
explicit SampleApp(ScopedShellHandle shell_handle)
: shell_(shell_handle.Pass(), this) {
InterfacePipe<NativeViewport, AnyInterface> pipe;
explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) {
InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;

AllocationScope scope;
shell_->Connect("mojo:mojo_native_viewport_service",
pipe.handle_to_peer.Pass());

native_viewport_client_.reset(
new NativeViewportClientImpl(pipe.handle_to_self.Pass()));
shell()->Connect("mojo:mojo_native_viewport_service",
viewport_pipe.handle_to_peer.Pass());

viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
viewport_->Create(gfx::Rect(10, 10, 800, 600));
viewport_->Show();
ScopedMessagePipeHandle gles2_handle;
ScopedMessagePipeHandle gles2_client_handle;
CreateMessagePipe(&gles2_handle, &gles2_client_handle);

viewport_->CreateGLES2Context(gles2_client_handle.Pass());
host_.reset(new CompositorHost(gles2_handle.Pass()));
}

virtual void AcceptConnection(const mojo::String& url,
ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
NOTREACHED() << "SampleApp can't be connected to.";
virtual void OnCreated() MOJO_OVERRIDE {
}

private:
class NativeViewportClientImpl : public NativeViewportClient {
public:
explicit NativeViewportClientImpl(
ScopedNativeViewportHandle viewport_handle)
: viewport_(viewport_handle.Pass(), this) {
AllocationScope allocation;
viewport_->Create(gfx::Rect(10, 10, 800, 600));
viewport_->Show();
ScopedMessagePipeHandle gles2_handle;
ScopedMessagePipeHandle gles2_client_handle;
CreateMessagePipe(&gles2_handle, &gles2_client_handle);

viewport_->CreateGLES2Context(gles2_client_handle.Pass());
host_.reset(new CompositorHost(gles2_handle.Pass()));
}

virtual ~NativeViewportClientImpl() {}

virtual void OnCreated() MOJO_OVERRIDE {
}

virtual void OnDestroyed() MOJO_OVERRIDE {
base::MessageLoop::current()->Quit();
}
virtual void OnDestroyed() MOJO_OVERRIDE {
base::MessageLoop::current()->Quit();
}

virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE {
host_->SetSize(bounds.size());
}
virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE {
host_->SetSize(bounds.size());
}

virtual void OnEvent(const Event& event) MOJO_OVERRIDE {
if (!event.location().is_null()) {
viewport_->AckEvent(event);
}
virtual void OnEvent(const Event& event) MOJO_OVERRIDE {
if (!event.location().is_null()) {
viewport_->AckEvent(event);
}
}

private:
RemotePtr<NativeViewport> viewport_;
scoped_ptr<CompositorHost> host_;
};
RemotePtr<Shell> shell_;
scoped_ptr<NativeViewportClientImpl> native_viewport_client_;
private:
RemotePtr<NativeViewport> viewport_;
scoped_ptr<CompositorHost> host_;
};

} // namespace examples
Expand All @@ -101,10 +81,7 @@ extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
base::MessageLoop loop;
mojo::GLES2Initializer gles2;

mojo::examples::SampleApp app(
mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass());

mojo::examples::SampleApp app(shell_handle);
loop.Run();

return MOJO_RESULT_OK;
}
19 changes: 9 additions & 10 deletions mojo/examples/launcher/launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/gles2/gles2_cpp.h"
#include "mojo/public/shell/application.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
#include "mojom/launcher.h"
Expand Down Expand Up @@ -187,30 +188,30 @@ class LauncherController : public views::TextfieldController {
DISALLOW_COPY_AND_ASSIGN(LauncherController);
};

class LauncherImpl : public ShellClient,
class LauncherImpl : public Application,
public Launcher,
public URLReceiver {
public:
explicit LauncherImpl(ScopedShellHandle shell_handle)
: launcher_controller_(this),
shell_(shell_handle.Pass(), this),
explicit LauncherImpl(MojoHandle shell_handle)
: Application(shell_handle),
launcher_controller_(this),
pending_show_(false) {
screen_.reset(DemoScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());

InterfacePipe<NativeViewport, AnyInterface> pipe;

AllocationScope scope;
shell_->Connect("mojo:mojo_native_viewport_service",
pipe.handle_to_peer.Pass());
shell()->Connect("mojo:mojo_native_viewport_service",
pipe.handle_to_peer.Pass());

root_window_host_.reset(new WindowTreeHostMojo(
pipe.handle_to_self.Pass(), gfx::Rect(50, 50, 450, 60),
base::Bind(&LauncherImpl::HostContextCreated, base::Unretained(this))));
}

private:
// Overridden from ShellClient:
// Overridden from Application:
virtual void AcceptConnection(const mojo::String& url,
ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
launcher_client_.reset(
Expand Down Expand Up @@ -272,7 +273,6 @@ class LauncherImpl : public ShellClient,

LauncherController launcher_controller_;

RemotePtr<Shell> shell_;
RemotePtr<LauncherClient> launcher_client_;
scoped_ptr<WindowTreeHostMojo> root_window_host_;
scoped_ptr<aura::RootWindow> root_window_;
Expand Down Expand Up @@ -302,8 +302,7 @@ extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain(
// MessageLoop is not of TYPE_UI. I think we need a way to build
// Aura that doesn't define platform-specific stuff.
aura::Env::CreateInstance();
mojo::examples::LauncherImpl launcher(
mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass());
mojo::examples::LauncherImpl launcher(shell_handle);
loop.Run();

return MOJO_RESULT_OK;
Expand Down
4 changes: 2 additions & 2 deletions mojo/examples/sample_app/sample_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class SampleApp : public Application, public mojo::NativeViewportClient {
explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) {
InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;
mojo::AllocationScope scope;
GetShell()->Connect("mojo:mojo_native_viewport_service",
viewport_pipe.handle_to_peer.Pass());
shell()->Connect("mojo:mojo_native_viewport_service",
viewport_pipe.handle_to_peer.Pass());
viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
Rect::Builder rect;
Point::Builder point;
Expand Down
31 changes: 10 additions & 21 deletions mojo/examples/view_manager/view_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/message_loop/message_loop.h"
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/shell/application.h"
#include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h"
#include "mojo/services/native_viewport/geometry_conversions.h"
Expand Down Expand Up @@ -55,13 +56,11 @@ class ViewImpl : public View {
DISALLOW_COPY_AND_ASSIGN(ViewImpl);
};

class ViewManagerImpl : public ViewManager,
public ShellClient,
class ViewManagerImpl : public Service<ViewManager, ViewManagerImpl>,
public NativeViewportClient,
public LauncherClient {
public:
explicit ViewManagerImpl(ScopedShellHandle shell_handle)
: shell_(shell_handle.Pass(), this) {
explicit ViewManagerImpl() {
InitNativeViewport();
}

Expand All @@ -70,16 +69,7 @@ class ViewManagerImpl : public ViewManager,
virtual void CreateView() MOJO_OVERRIDE {
InterfacePipe<View> pipe;
views_.push_back(new ViewImpl(pipe.handle_to_peer.Pass()));
client_->OnViewCreated(pipe.handle_to_self.Pass());
}

// Overridden from ShellClient:
virtual void AcceptConnection(const mojo::String& url,
ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
client_.reset(
MakeScopedHandle(
ViewManagerClientHandle(handle.release().value())).Pass(),
this);
client()->OnViewCreated(pipe.handle_to_self.Pass());
}

// Overridden from NativeViewportClient:
Expand Down Expand Up @@ -114,8 +104,8 @@ class ViewManagerImpl : public ViewManager,
InterfacePipe<NativeViewport, AnyInterface> pipe;

AllocationScope scope;
shell_->Connect("mojo:mojo_native_viewport_service",
pipe.handle_to_peer.Pass());
shell()->Connect("mojo:mojo_native_viewport_service",
pipe.handle_to_peer.Pass());

native_viewport_.reset(pipe.handle_to_self.Pass(), this);
native_viewport_->Create(gfx::Rect(50, 50, 800, 600));
Expand All @@ -129,16 +119,14 @@ class ViewManagerImpl : public ViewManager,
InterfacePipe<Launcher, AnyInterface> pipe;

AllocationScope scope;
shell_->Connect("mojo:mojo_launcher", pipe.handle_to_peer.Pass());
shell()->Connect("mojo:mojo_launcher", pipe.handle_to_peer.Pass());

launcher_.reset(pipe.handle_to_self.Pass(), this);
}

void DidCreateContext() {
}

RemotePtr<Shell> shell_;
RemotePtr<ViewManagerClient> client_;
ScopedVector<ViewImpl> views_;
RemotePtr<NativeViewport> native_viewport_;
RemotePtr<Launcher> launcher_;
Expand All @@ -152,8 +140,9 @@ class ViewManagerImpl : public ViewManager,
extern "C" VIEW_MANAGER_EXPORT MojoResult CDECL MojoMain(
MojoHandle shell_handle) {
base::MessageLoop loop;
mojo::examples::ViewManagerImpl view_manager(
mojo::MakeScopedHandle(mojo::ShellHandle(shell_handle)).Pass());
mojo::Application app(shell_handle);
app.AddServiceFactory(
new mojo::ServiceFactory<mojo::examples::ViewManagerImpl>);
loop.Run();

return MOJO_RESULT_OK;
Expand Down
5 changes: 1 addition & 4 deletions mojo/public/shell/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@

namespace mojo {

class Application : public internal::ServiceFactoryBase::Owner,
public ShellClient {
class Application : public internal::ServiceFactoryBase::Owner {
public:
explicit Application(ScopedShellHandle shell_handle);
explicit Application(MojoHandle shell_handle);
virtual ~Application();

// internal::ServiceFactoryBase::Owner methods.
virtual Shell* GetShell() MOJO_OVERRIDE;
// Takes ownership of |service_factory|.
virtual void AddServiceFactory(internal::ServiceFactoryBase* service_factory)
MOJO_OVERRIDE;
Expand All @@ -38,7 +36,6 @@ class Application : public internal::ServiceFactoryBase::Owner,
private:
typedef std::vector<internal::ServiceFactoryBase*> ServiceFactoryList;
ServiceFactoryList service_factories_;
RemotePtr<Shell> shell_;
};

} // namespace mojo
Expand Down
9 changes: 3 additions & 6 deletions mojo/public/shell/lib/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
namespace mojo {

Application::Application(ScopedShellHandle shell_handle)
: shell_(shell_handle.Pass(), this) {
: internal::ServiceFactoryBase::Owner(shell_handle.Pass()) {
}

Application::Application(MojoHandle shell_handle)
: shell_(mojo::MakeScopedHandle(ShellHandle(shell_handle)).Pass()) {}
: internal::ServiceFactoryBase::Owner(
mojo::MakeScopedHandle(ShellHandle(shell_handle)).Pass()) {}

Application::~Application() {
for (ServiceFactoryList::iterator it = service_factories_.begin();
Expand All @@ -20,10 +21,6 @@ Application::~Application() {
}
}

Shell* Application::GetShell() {
return shell_.get();
}

void Application::AddServiceFactory(
internal::ServiceFactoryBase* service_factory) {
service_factories_.push_back(service_factory);
Expand Down
Loading

0 comments on commit 06863b3

Please sign in to comment.