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

Side by Side Diff: mojo/examples/sample_app/sample_app.cc

Issue 93793009: Implement ServiceManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Allow Android to be built Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/examples/sample_app/native_viewport_client_impl.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <string> 6 #include <string>
7 7
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "mojo/common/bindings_support_impl.h" 9 #include "mojo/common/bindings_support_impl.h"
10 #include "mojo/examples/sample_app/native_viewport_client_impl.h" 10 #include "mojo/examples/sample_app/gles2_client_impl.h"
11 #include "mojo/public/bindings/lib/bindings_support.h" 11 #include "mojo/public/bindings/lib/bindings_support.h"
12 #include "mojo/public/bindings/lib/remote_ptr.h"
12 #include "mojo/public/gles2/gles2.h" 13 #include "mojo/public/gles2/gles2.h"
13 #include "mojo/public/system/core.h" 14 #include "mojo/public/system/core.h"
14 #include "mojo/public/system/macros.h" 15 #include "mojo/public/system/macros.h"
16 #include "mojom/native_viewport.h"
17 #include "mojom/shell.h"
15 18
16 #if defined(WIN32) 19 #if defined(WIN32)
17 #if !defined(CDECL) 20 #if !defined(CDECL)
18 #define CDECL __cdecl 21 #define CDECL __cdecl
19 #endif 22 #endif
20 #define SAMPLE_APP_EXPORT __declspec(dllexport) 23 #define SAMPLE_APP_EXPORT __declspec(dllexport)
21 #else 24 #else
22 #define CDECL 25 #define CDECL
23 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) 26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
24 #endif 27 #endif
25 28
26 namespace mojo { 29 namespace mojo {
27 namespace examples { 30 namespace examples {
28 31
29 void Start(ScopedMessagePipeHandle pipe) { 32 class SampleApp : public ShellClientStub {
30 printf("Starting sample app.\n"); 33 public:
31 NativeViewportClientImpl client(pipe.Pass()); 34 explicit SampleApp(ScopedMessagePipeHandle shell_handle)
32 client.Open(); 35 : shell_(shell_handle.Pass()) {
33 base::MessageLoop::current()->Run(); 36 shell_.SetPeer(this);
34 } 37 mojo::ScopedMessagePipeHandle client_handle, native_viewport_handle;
38 CreateMessagePipe(&client_handle, &native_viewport_handle);
39 native_viewport_client_.reset(
40 new NativeViewportClientImpl(native_viewport_handle.Pass()));
41 mojo::AllocationScope scope;
42 shell_->Connect("mojo:mojo_native_viewport_service", client_handle.Pass());
43 }
44
45 virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
46 NOTREACHED() << "SampleApp can't be connected to.";
47 }
48
49 private:
50 class NativeViewportClientImpl : public mojo::NativeViewportClientStub {
51 public:
52 explicit NativeViewportClientImpl(ScopedMessagePipeHandle viewport_handle)
53 : viewport_(viewport_handle.Pass()) {
54 viewport_.SetPeer(this);
55 viewport_->Open();
56 ScopedMessagePipeHandle gles2_handle;
57 ScopedMessagePipeHandle gles2_client_handle;
58 CreateMessagePipe(&gles2_handle, &gles2_client_handle);
59
60 gles2_client_.reset(new GLES2ClientImpl(gles2_handle.Pass()));
61 viewport_->CreateGLES2Context(gles2_client_handle.Pass());
62 }
63
64 virtual ~NativeViewportClientImpl() {}
65
66 virtual void OnCreated() MOJO_OVERRIDE {
67 }
68
69 virtual void OnDestroyed() MOJO_OVERRIDE {
70 base::MessageLoop::current()->Quit();
71 }
72
73 virtual void OnEvent(const Event& event) MOJO_OVERRIDE {
74 if (!event.location().is_null()) {
75 gles2_client_->HandleInputEvent(event);
76 viewport_->AckEvent(event);
77 }
78 }
79
80 private:
81 scoped_ptr<GLES2ClientImpl> gles2_client_;
82 RemotePtr<NativeViewport> viewport_;
83 };
84 mojo::RemotePtr<Shell> shell_;
85 scoped_ptr<NativeViewportClientImpl> native_viewport_client_;
86 };
35 87
36 } // namespace examples 88 } // namespace examples
37 } // namespace mojo 89 } // namespace mojo
38 90
39 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) { 91 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
92 MojoHandle shell_handle) {
40 base::MessageLoop loop; 93 base::MessageLoop loop;
41 mojo::common::BindingsSupportImpl bindings_support; 94 mojo::common::BindingsSupportImpl bindings_support_impl;
42 mojo::BindingsSupport::Set(&bindings_support); 95 mojo::BindingsSupport::Set(&bindings_support_impl);
43 MojoGLES2Initialize(); 96 MojoGLES2Initialize();
44 97
45 mojo::ScopedMessagePipeHandle scoped_handle; 98 mojo::examples::SampleApp app(
46 scoped_handle.reset(mojo::MessagePipeHandle(pipe)); 99 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass());
47 mojo::examples::Start(scoped_handle.Pass()); 100 loop.Run();
48 101
49 MojoGLES2Terminate(); 102 MojoGLES2Terminate();
50 mojo::BindingsSupport::Set(NULL); 103 mojo::BindingsSupport::Set(NULL);
51 return MOJO_RESULT_OK; 104 return MOJO_RESULT_OK;
52 } 105 }
OLDNEW
« no previous file with comments | « mojo/examples/sample_app/native_viewport_client_impl.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698