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

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

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 months 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
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 "mojo/examples/sample_app/gles2_client_impl.h" 8 #include "mojo/examples/sample_app/gles2_client_impl.h"
9 #include "mojo/public/cpp/bindings/allocation_scope.h" 9 #include "mojo/public/cpp/bindings/allocation_scope.h"
10 #include "mojo/public/cpp/bindings/remote_ptr.h"
11 #include "mojo/public/cpp/environment/environment.h" 10 #include "mojo/public/cpp/environment/environment.h"
12 #include "mojo/public/cpp/gles2/gles2.h" 11 #include "mojo/public/cpp/gles2/gles2.h"
13 #include "mojo/public/cpp/shell/application.h" 12 #include "mojo/public/cpp/shell/application.h"
14 #include "mojo/public/cpp/system/core.h" 13 #include "mojo/public/cpp/system/core.h"
15 #include "mojo/public/cpp/system/macros.h" 14 #include "mojo/public/cpp/system/macros.h"
16 #include "mojo/public/cpp/utility/run_loop.h" 15 #include "mojo/public/cpp/utility/run_loop.h"
17 #include "mojo/public/interfaces/shell/shell.mojom.h" 16 #include "mojo/public/interfaces/shell/shell.mojom.h"
18 #include "mojo/services/native_viewport/native_viewport.mojom.h" 17 #include "mojo/services/native_viewport/native_viewport.mojom.h"
19 18
20 #if defined(WIN32) 19 #if defined(WIN32)
21 #if !defined(CDECL) 20 #if !defined(CDECL)
22 #define CDECL __cdecl 21 #define CDECL __cdecl
23 #endif 22 #endif
24 #define SAMPLE_APP_EXPORT __declspec(dllexport) 23 #define SAMPLE_APP_EXPORT __declspec(dllexport)
25 #else 24 #else
26 #define CDECL 25 #define CDECL
27 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) 26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
28 #endif 27 #endif
29 28
30 namespace mojo { 29 namespace mojo {
31 namespace examples { 30 namespace examples {
32 31
33 class SampleApp : public Application, public mojo::NativeViewportClient { 32 class SampleApp : public Application, public NativeViewportClient {
34 public: 33 public:
35 explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) { 34 explicit SampleApp(MojoHandle shell_handle) : Application(shell_handle) {
36 InterfacePipe<NativeViewport, AnyInterface> viewport_pipe; 35 ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
37 mojo::AllocationScope scope; 36 viewport_->SetClient(this);
38 shell()->Connect("mojo:mojo_native_viewport_service", 37
39 viewport_pipe.handle_to_peer.Pass()); 38 AllocationScope scope;
40 viewport_.reset(viewport_pipe.handle_to_self.Pass(), this); 39
41 Rect::Builder rect; 40 Rect::Builder rect;
42 Point::Builder point; 41 Point::Builder point;
43 point.set_x(10); 42 point.set_x(10);
44 point.set_y(10); 43 point.set_y(10);
45 rect.set_position(point.Finish()); 44 rect.set_position(point.Finish());
46 Size::Builder size; 45 Size::Builder size;
47 size.set_width(800); 46 size.set_width(800);
48 size.set_height(600); 47 size.set_height(600);
49 rect.set_size(size.Finish()); 48 rect.set_size(size.Finish());
50 viewport_->Create(rect.Finish()); 49 viewport_->Create(rect.Finish());
51 viewport_->Show(); 50 viewport_->Show();
52 51
53 MessagePipe gles2_pipe; 52 MessagePipe gles2_pipe;
54 viewport_->CreateGLES2Context(gles2_pipe.handle1.Pass()); 53 viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass());
55 gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle0.Pass())); 54 gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle1.Pass()));
56 } 55 }
57 56
58 virtual ~SampleApp() { 57 virtual ~SampleApp() {
59 // TODO(darin): Fix shutdown so we don't need to leak this. 58 // TODO(darin): Fix shutdown so we don't need to leak this.
60 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release(); 59 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release();
61 } 60 }
62 61
63 virtual void OnCreated() MOJO_OVERRIDE { 62 virtual void OnCreated() MOJO_OVERRIDE {
64 } 63 }
65 64
66 virtual void OnDestroyed() MOJO_OVERRIDE { 65 virtual void OnDestroyed() MOJO_OVERRIDE {
67 RunLoop::current()->Quit(); 66 RunLoop::current()->Quit();
68 } 67 }
69 68
70 virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE { 69 virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE {
71 gles2_client_->SetSize(bounds.size()); 70 gles2_client_->SetSize(bounds.size());
72 } 71 }
73 72
74 virtual void OnEvent(const Event& event, 73 virtual void OnEvent(const Event& event,
75 const mojo::Callback<void()>& callback) MOJO_OVERRIDE { 74 const Callback<void()>& callback) MOJO_OVERRIDE {
76 if (!event.location().is_null()) 75 if (!event.location().is_null())
77 gles2_client_->HandleInputEvent(event); 76 gles2_client_->HandleInputEvent(event);
78 callback.Run(); 77 callback.Run();
79 } 78 }
80 79
81 private: 80 private:
82 scoped_ptr<GLES2ClientImpl> gles2_client_; 81 scoped_ptr<GLES2ClientImpl> gles2_client_;
83 RemotePtr<NativeViewport> viewport_; 82 NativeViewportPtr viewport_;
84 }; 83 };
85 84
86 } // namespace examples 85 } // namespace examples
87 } // namespace mojo 86 } // namespace mojo
88 87
89 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( 88 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
90 MojoHandle shell_handle) { 89 MojoHandle shell_handle) {
91 mojo::Environment env; 90 mojo::Environment env;
92 mojo::RunLoop loop; 91 mojo::RunLoop loop;
93 mojo::GLES2Initializer gles2; 92 mojo::GLES2Initializer gles2;
94 93
95 mojo::examples::SampleApp app(shell_handle); 94 mojo::examples::SampleApp app(shell_handle);
96 loop.Run(); 95 loop.Run();
97 return MOJO_RESULT_OK; 96 return MOJO_RESULT_OK;
98 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698