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

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

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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
« no previous file with comments | « mojo/examples/sample_app/gles2_client_impl.cc ('k') | mojo/gles2/command_buffer_client_impl.h » ('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 "mojo/examples/sample_app/gles2_client_impl.h" 8 #include "mojo/examples/sample_app/gles2_client_impl.h"
9 #include "mojo/public/cpp/application/application.h" 9 #include "mojo/public/cpp/application/application.h"
10 #include "mojo/public/cpp/bindings/allocation_scope.h"
11 #include "mojo/public/cpp/gles2/gles2.h" 10 #include "mojo/public/cpp/gles2/gles2.h"
12 #include "mojo/public/cpp/system/core.h" 11 #include "mojo/public/cpp/system/core.h"
13 #include "mojo/public/cpp/system/macros.h" 12 #include "mojo/public/cpp/system/macros.h"
14 #include "mojo/public/cpp/utility/run_loop.h" 13 #include "mojo/public/cpp/utility/run_loop.h"
15 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" 14 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
16 #include "mojo/services/native_viewport/native_viewport.mojom.h" 15 #include "mojo/services/native_viewport/native_viewport.mojom.h"
17 16
18 namespace mojo { 17 namespace mojo {
19 namespace examples { 18 namespace examples {
20 19
21 class SampleApp : public Application, public NativeViewportClient { 20 class SampleApp : public Application, public NativeViewportClient {
22 public: 21 public:
23 SampleApp() {} 22 SampleApp() {}
24 23
25 virtual ~SampleApp() { 24 virtual ~SampleApp() {
26 // TODO(darin): Fix shutdown so we don't need to leak this. 25 // TODO(darin): Fix shutdown so we don't need to leak this.
27 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release(); 26 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release();
28 } 27 }
29 28
30 virtual void Initialize() MOJO_OVERRIDE { 29 virtual void Initialize() MOJO_OVERRIDE {
31 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); 30 ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
32 viewport_.set_client(this); 31 viewport_.set_client(this);
33 32
34 AllocationScope scope; 33 RectPtr rect(Rect::New());
35 Rect::Builder rect; 34 rect->x = 10;
36 rect.set_x(10); 35 rect->y = 10;
37 rect.set_y(10); 36 rect->width = 800;
38 rect.set_width(800); 37 rect->height = 600;
39 rect.set_height(600); 38 viewport_->Create(rect.Pass());
40 viewport_->Create(rect.Finish());
41 viewport_->Show(); 39 viewport_->Show();
42 40
43 MessagePipe gles2_pipe; 41 MessagePipe gles2_pipe;
44 viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass()); 42 viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass());
45 gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle1.Pass())); 43 gles2_client_.reset(new GLES2ClientImpl(gles2_pipe.handle1.Pass()));
46 } 44 }
47 45
48 virtual void OnCreated() MOJO_OVERRIDE { 46 virtual void OnCreated() MOJO_OVERRIDE {
49 } 47 }
50 48
51 virtual void OnDestroyed() MOJO_OVERRIDE { 49 virtual void OnDestroyed() MOJO_OVERRIDE {
52 RunLoop::current()->Quit(); 50 RunLoop::current()->Quit();
53 } 51 }
54 52
55 virtual void OnBoundsChanged(const Rect& bounds) MOJO_OVERRIDE { 53 virtual void OnBoundsChanged(RectPtr bounds) MOJO_OVERRIDE {
56 AllocationScope scope; 54 assert(bounds);
57 Size::Builder size; 55 SizePtr size(Size::New());
58 size.set_width(bounds.width()); 56 size->width = bounds->width;
59 size.set_height(bounds.height()); 57 size->height = bounds->height;
60 gles2_client_->SetSize(size.Finish()); 58 gles2_client_->SetSize(*size);
61 } 59 }
62 60
63 virtual void OnEvent(const Event& event, 61 virtual void OnEvent(EventPtr event,
64 const Callback<void()>& callback) MOJO_OVERRIDE { 62 const Callback<void()>& callback) MOJO_OVERRIDE {
65 if (!event.location().is_null()) 63 assert(event);
66 gles2_client_->HandleInputEvent(event); 64 if (event->location)
65 gles2_client_->HandleInputEvent(*event);
67 callback.Run(); 66 callback.Run();
68 } 67 }
69 68
70 private: 69 private:
71 mojo::GLES2Initializer gles2; 70 mojo::GLES2Initializer gles2;
72 scoped_ptr<GLES2ClientImpl> gles2_client_; 71 scoped_ptr<GLES2ClientImpl> gles2_client_;
73 NativeViewportPtr viewport_; 72 NativeViewportPtr viewport_;
74 73
75 DISALLOW_COPY_AND_ASSIGN(SampleApp); 74 DISALLOW_COPY_AND_ASSIGN(SampleApp);
76 }; 75 };
77 76
78 } // namespace examples 77 } // namespace examples
79 78
80 // static 79 // static
81 Application* Application::Create() { 80 Application* Application::Create() {
82 return new examples::SampleApp(); 81 return new examples::SampleApp();
83 } 82 }
84 83
85 } // namespace mojo 84 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/sample_app/gles2_client_impl.cc ('k') | mojo/gles2/command_buffer_client_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698