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

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

Issue 478103002: Revert of Mojo multiple command buffer support and sample (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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/application/application_connection.h" 9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/application_delegate.h" 10 #include "mojo/public/cpp/application/application_delegate.h"
11 #include "mojo/public/cpp/application/application_impl.h" 11 #include "mojo/public/cpp/application/application_impl.h"
12 #include "mojo/public/cpp/system/core.h" 12 #include "mojo/public/cpp/system/core.h"
13 #include "mojo/public/cpp/system/macros.h" 13 #include "mojo/public/cpp/system/macros.h"
14 #include "mojo/public/cpp/utility/run_loop.h" 14 #include "mojo/public/cpp/utility/run_loop.h"
15 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
16 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h" 15 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom. h"
17 16
18 namespace examples { 17 namespace examples {
19 18
20 class SampleApp : public mojo::ApplicationDelegate, 19 class SampleApp : public mojo::ApplicationDelegate,
21 public mojo::NativeViewportClient { 20 public mojo::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::ApplicationImpl* app) MOJO_OVERRIDE { 29 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
31 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); 30 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_);
32 viewport_.set_client(this); 31 viewport_.set_client(this);
33 32
34 // TODO(jamesr): Should be mojo:mojo_gpu_service
35 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_);
36
37 mojo::RectPtr rect(mojo::Rect::New()); 33 mojo::RectPtr rect(mojo::Rect::New());
38 rect->x = 10; 34 rect->x = 10;
39 rect->y = 10; 35 rect->y = 10;
40 rect->width = 800; 36 rect->width = 800;
41 rect->height = 600; 37 rect->height = 600;
42 viewport_->Create(rect.Pass()); 38 viewport_->Create(rect.Pass());
43 viewport_->Show(); 39 viewport_->Show();
44 }
45 40
46 virtual void OnCreated(uint64_t native_viewport_id) MOJO_OVERRIDE {
47 mojo::SizePtr size = mojo::Size::New();
48 size->width = 800;
49 size->height = 600;
50 mojo::CommandBufferPtr command_buffer; 41 mojo::CommandBufferPtr command_buffer;
51 gpu_service_->CreateOnscreenGLES2Context( 42 viewport_->CreateGLES2Context(Get(&command_buffer));
52 native_viewport_id, size.Pass(), Get(&command_buffer));
53 gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass())); 43 gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass()));
54 } 44 }
55 45
56 virtual void OnDestroyed() MOJO_OVERRIDE { mojo::RunLoop::current()->Quit(); } 46 virtual void OnCreated() MOJO_OVERRIDE {
47 }
48
49 virtual void OnDestroyed(
50 const mojo::Callback<void()>& callback) MOJO_OVERRIDE {
51 mojo::RunLoop::current()->Quit();
52 callback.Run();
53 }
57 54
58 virtual void OnBoundsChanged(mojo::RectPtr bounds) MOJO_OVERRIDE { 55 virtual void OnBoundsChanged(mojo::RectPtr bounds) MOJO_OVERRIDE {
59 assert(bounds); 56 assert(bounds);
60 mojo::SizePtr size(mojo::Size::New()); 57 mojo::SizePtr size(mojo::Size::New());
61 size->width = bounds->width; 58 size->width = bounds->width;
62 size->height = bounds->height; 59 size->height = bounds->height;
63 if (gles2_client_) 60 gles2_client_->SetSize(*size);
64 gles2_client_->SetSize(*size);
65 } 61 }
66 62
67 virtual void OnEvent(mojo::EventPtr event, 63 virtual void OnEvent(mojo::EventPtr event,
68 const mojo::Callback<void()>& callback) MOJO_OVERRIDE { 64 const mojo::Callback<void()>& callback) MOJO_OVERRIDE {
69 assert(event); 65 assert(event);
70 if (event->location) 66 if (event->location)
71 gles2_client_->HandleInputEvent(*event); 67 gles2_client_->HandleInputEvent(*event);
72 callback.Run(); 68 callback.Run();
73 } 69 }
74 70
75 private: 71 private:
76 scoped_ptr<GLES2ClientImpl> gles2_client_; 72 scoped_ptr<GLES2ClientImpl> gles2_client_;
77 mojo::NativeViewportPtr viewport_; 73 mojo::NativeViewportPtr viewport_;
78 mojo::GpuPtr gpu_service_;
79 74
80 DISALLOW_COPY_AND_ASSIGN(SampleApp); 75 DISALLOW_COPY_AND_ASSIGN(SampleApp);
81 }; 76 };
82 77
83 } // namespace examples 78 } // namespace examples
84 79
85 namespace mojo { 80 namespace mojo {
86 81
87 // static 82 // static
88 ApplicationDelegate* ApplicationDelegate::Create() { 83 ApplicationDelegate* ApplicationDelegate::Create() {
89 return new examples::SampleApp(); 84 return new examples::SampleApp();
90 } 85 }
91 86
92 } // namespace mojo 87 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/pepper_container_app/pepper_container_app.cc ('k') | mojo/examples/surfaces_app/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698