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

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

Issue 684543003: Move //mojo/examples to //examples (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « mojo/examples/sample_app/gles2_client_impl.cc ('k') | mojo/examples/sample_app/spinning_cube.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include <stdio.h>
6 #include <string>
7
8 #include "base/bind.h"
9 #include "base/memory/weak_ptr.h"
10 #include "mojo/examples/sample_app/gles2_client_impl.h"
11 #include "mojo/public/c/system/main.h"
12 #include "mojo/public/cpp/application/application_connection.h"
13 #include "mojo/public/cpp/application/application_delegate.h"
14 #include "mojo/public/cpp/application/application_impl.h"
15 #include "mojo/public/cpp/application/application_runner.h"
16 #include "mojo/public/cpp/system/core.h"
17 #include "mojo/public/cpp/system/macros.h"
18 #include "mojo/public/cpp/utility/run_loop.h"
19 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
20 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h"
21
22 namespace examples {
23
24 class SampleApp : public mojo::ApplicationDelegate,
25 public mojo::NativeViewportClient {
26 public:
27 SampleApp() : weak_factory_(this) {}
28
29 virtual ~SampleApp() {
30 // TODO(darin): Fix shutdown so we don't need to leak this.
31 mojo_ignore_result(gles2_client_.release());
32 }
33
34 virtual void Initialize(mojo::ApplicationImpl* app) override {
35 app->ConnectToService("mojo:native_viewport_service", &viewport_);
36 viewport_.set_client(this);
37
38 // TODO(jamesr): Should be mojo:gpu_service
39 app->ConnectToService("mojo:native_viewport_service", &gpu_service_);
40
41 mojo::SizePtr size(mojo::Size::New());
42 size->width = 800;
43 size->height = 600;
44 viewport_->Create(size.Pass(),
45 base::Bind(&SampleApp::OnCreatedNativeViewport,
46 weak_factory_.GetWeakPtr()));
47 viewport_->Show();
48 }
49
50 virtual void OnDestroyed() override { mojo::RunLoop::current()->Quit(); }
51
52 virtual void OnSizeChanged(mojo::SizePtr size) override {
53 assert(size);
54 if (gles2_client_)
55 gles2_client_->SetSize(*size);
56 }
57
58 virtual void OnEvent(mojo::EventPtr event,
59 const mojo::Callback<void()>& callback) override {
60 assert(event);
61 if (event->location_data && event->location_data->in_view_location)
62 gles2_client_->HandleInputEvent(*event);
63 callback.Run();
64 }
65
66 private:
67 void OnCreatedNativeViewport(uint64_t native_viewport_id) {
68 mojo::SizePtr size = mojo::Size::New();
69 size->width = 800;
70 size->height = 600;
71 mojo::CommandBufferPtr command_buffer;
72 // TODO(jamesr): Output to a surface instead.
73 gpu_service_->CreateOnscreenGLES2Context(
74 native_viewport_id, size.Pass(), GetProxy(&command_buffer));
75 gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass()));
76 }
77
78 scoped_ptr<GLES2ClientImpl> gles2_client_;
79 mojo::NativeViewportPtr viewport_;
80 mojo::GpuPtr gpu_service_;
81 base::WeakPtrFactory<SampleApp> weak_factory_;
82
83 DISALLOW_COPY_AND_ASSIGN(SampleApp);
84 };
85
86 } // namespace examples
87
88 MojoResult MojoMain(MojoHandle shell_handle) {
89 mojo::ApplicationRunner runner(new examples::SampleApp);
90 return runner.Run(shell_handle);
91 }
OLDNEW
« no previous file with comments | « mojo/examples/sample_app/gles2_client_impl.cc ('k') | mojo/examples/sample_app/spinning_cube.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698