Disable signin-to-Chrome when using Guest profile.
[chromium-blink-merge.git] / mojo / examples / sample_app / sample_app.cc
blob6c078e10731b78236755867e3e5b60552c25f71c
1 // Copyright 2013 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.
5 #include <stdio.h>
6 #include <string>
8 #include "mojo/examples/sample_app/gles2_client_impl.h"
9 #include "mojo/public/bindings/allocation_scope.h"
10 #include "mojo/public/bindings/remote_ptr.h"
11 #include "mojo/public/environment/environment.h"
12 #include "mojo/public/gles2/gles2_cpp.h"
13 #include "mojo/public/shell/application.h"
14 #include "mojo/public/shell/shell.mojom.h"
15 #include "mojo/public/system/core.h"
16 #include "mojo/public/system/macros.h"
17 #include "mojo/public/utility/run_loop.h"
18 #include "mojo/services/native_viewport/native_viewport.mojom.h"
20 #if defined(WIN32)
21 #if !defined(CDECL)
22 #define CDECL __cdecl
23 #endif
24 #define SAMPLE_APP_EXPORT __declspec(dllexport)
25 #else
26 #define CDECL
27 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
28 #endif
30 namespace mojo {
31 namespace examples {
33 class SampleApp : public Application, public mojo::NativeViewportClient {
34 public:
35 explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) {
36 InterfacePipe<NativeViewport, AnyInterface> viewport_pipe;
37 mojo::AllocationScope scope;
38 shell()->Connect("mojo:mojo_native_viewport_service",
39 viewport_pipe.handle_to_peer.Pass());
40 viewport_.reset(viewport_pipe.handle_to_self.Pass(), this);
41 Rect::Builder rect;
42 Point::Builder point;
43 point.set_x(10);
44 point.set_y(10);
45 rect.set_position(point.Finish());
46 Size::Builder size;
47 size.set_width(800);
48 size.set_height(600);
49 rect.set_size(size.Finish());
50 viewport_->Create(rect.Finish());
51 viewport_->Show();
53 MessagePipe gles2_pipe;
54 viewport_->CreateGLES2Context(gles2_pipe.handle1.Pass());
55 gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle0.Pass()));
58 virtual ~SampleApp() {
59 // TODO(darin): Fix shutdown so we don't need to leak this.
60 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release();
63 virtual void OnCreated() MOJO_OVERRIDE {
66 virtual void OnDestroyed() MOJO_OVERRIDE {
67 RunLoop::current()->Quit();
70 virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE {
71 gles2_client_->SetSize(bounds.size());
74 virtual void OnEvent(const Event& event) MOJO_OVERRIDE {
75 if (!event.location().is_null()) {
76 gles2_client_->HandleInputEvent(event);
77 viewport_->AckEvent(event);
81 private:
82 scoped_ptr<GLES2ClientImpl> gles2_client_;
83 RemotePtr<NativeViewport> viewport_;
86 } // namespace examples
87 } // namespace mojo
89 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
90 MojoHandle shell_handle) {
91 mojo::Environment env;
92 mojo::RunLoop loop;
93 mojo::GLES2Initializer gles2;
95 mojo::examples::SampleApp app(shell_handle);
96 loop.Run();
97 return MOJO_RESULT_OK;