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

Side by Side Diff: examples/surfaces_app/surfaces_app.cc

Issue 940293003: Add a Display and ContextProvider concept to mojom, use to recreate (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « examples/surfaces_app/embedder.cc ('k') | mojo/services/gpu/public/interfaces/BUILD.gn » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "cc/surfaces/surface_id_allocator.h" 9 #include "cc/surfaces/surface_id_allocator.h"
10 #include "examples/surfaces_app/child.mojom.h" 10 #include "examples/surfaces_app/child.mojom.h"
11 #include "examples/surfaces_app/embedder.h" 11 #include "examples/surfaces_app/embedder.h"
12 #include "mojo/application/application_runner_chromium.h" 12 #include "mojo/application/application_runner_chromium.h"
13 #include "mojo/converters/geometry/geometry_type_converters.h" 13 #include "mojo/converters/geometry/geometry_type_converters.h"
14 #include "mojo/converters/surfaces/surfaces_type_converters.h" 14 #include "mojo/converters/surfaces/surfaces_type_converters.h"
15 #include "mojo/public/c/system/main.h" 15 #include "mojo/public/c/system/main.h"
16 #include "mojo/public/cpp/application/application_connection.h" 16 #include "mojo/public/cpp/application/application_connection.h"
17 #include "mojo/public/cpp/application/application_delegate.h" 17 #include "mojo/public/cpp/application/application_delegate.h"
18 #include "mojo/public/cpp/application/application_impl.h" 18 #include "mojo/public/cpp/application/application_impl.h"
19 #include "mojo/public/cpp/system/core.h" 19 #include "mojo/public/cpp/system/core.h"
20 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h" 20 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h"
21 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" 21 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h"
22 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom. h" 22 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom. h"
23 #include "mojo/services/surfaces/public/interfaces/display.mojom.h"
23 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" 24 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h"
24 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
25 26
26 namespace mojo { 27 namespace mojo {
27 namespace examples { 28 namespace examples {
28 29
29 static const uint32_t kLocalId = 1u;
30
31 class SurfacesApp : public ApplicationDelegate { 30 class SurfacesApp : public ApplicationDelegate {
32 public: 31 public:
33 SurfacesApp() : app_impl_(nullptr), id_namespace_(0u), weak_factory_(this) {} 32 SurfacesApp() : app_impl_(nullptr), id_namespace_(0u), weak_factory_(this) {}
34 ~SurfacesApp() override {} 33 ~SurfacesApp() override {}
35 34
36 void Initialize(ApplicationImpl* app) override { app_impl_ = app; }
37
38 // ApplicationDelegate implementation 35 // ApplicationDelegate implementation
39 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 36 void Initialize(ApplicationImpl* app) override {
40 app_impl_->ConnectToService("mojo:native_viewport_service", &viewport_); 37 app_impl_ = app;
41
42 app_impl_->ConnectToService("mojo:surfaces_service", &surface_);
43 surface_->GetIdNamespace(
44 base::Bind(&SurfacesApp::SetIdNamespace, base::Unretained(this)));
45 embedder_.reset(new Embedder(kLocalId, surface_.get()));
46
47 size_ = gfx::Size(800, 600); 38 size_ = gfx::Size(800, 600);
48 39
49 viewport_->Create(Size::From(size_), 40 // Connect to the native viewport service and create a viewport.
50 base::Bind(&SurfacesApp::OnCreatedNativeViewport, 41 app_impl_->ConnectToService("mojo:native_viewport_service", &viewport_);
51 weak_factory_.GetWeakPtr())); 42 viewport_->Create(Size::From(size_), [](ViewportMetricsPtr metrics) {});
52 viewport_->Show(); 43 viewport_->Show();
53 44
45 // Grab a ContextProvider associated with the viewport.
46 ContextProviderPtr onscreen_context_provider;
47 viewport_->GetContextProvider(GetProxy(&onscreen_context_provider));
48
49 // Create a surfaces Display bound to the viewport's context provider.
50 DisplayFactoryPtr display_factory;
51 app_impl_->ConnectToService("mojo:surfaces_service", &display_factory);
52 display_factory->Create(onscreen_context_provider.Pass(),
53 nullptr, // resource_returner
54 GetProxy(&display_));
55
56 // Construct a mojo::examples::Embedder object that will draw to our
57 // display.
58 embedder_.reset(new Embedder(display_.get()));
59
54 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2); 60 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2);
55 app_impl_->ConnectToService("mojo:surfaces_child_app", &child_one_); 61 app_impl_->ConnectToService("mojo:surfaces_child_app", &child_one_);
56 app_impl_->ConnectToService("mojo:surfaces_child_gl_app", &child_two_); 62 app_impl_->ConnectToService("mojo:surfaces_child_gl_app", &child_two_);
57 child_one_->ProduceFrame(Color::From(SK_ColorBLUE), 63 child_one_->ProduceFrame(Color::From(SK_ColorBLUE),
58 Size::From(child_size_), 64 Size::From(child_size_),
59 base::Bind(&SurfacesApp::ChildOneProducedFrame, 65 base::Bind(&SurfacesApp::ChildOneProducedFrame,
60 base::Unretained(this))); 66 base::Unretained(this)));
61 child_two_->ProduceFrame(Color::From(SK_ColorGREEN), 67 child_two_->ProduceFrame(Color::From(SK_ColorGREEN),
62 Size::From(child_size_), 68 Size::From(child_size_),
63 base::Bind(&SurfacesApp::ChildTwoProducedFrame, 69 base::Bind(&SurfacesApp::ChildTwoProducedFrame,
64 base::Unretained(this))); 70 base::Unretained(this)));
65 surface_->CreateSurface(kLocalId);
66 Draw(10); 71 Draw(10);
67 return true; 72 }
73
74 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
75 return false;
68 } 76 }
69 77
70 void ChildOneProducedFrame(SurfaceIdPtr id) { 78 void ChildOneProducedFrame(SurfaceIdPtr id) {
71 child_one_id_ = id.To<cc::SurfaceId>(); 79 child_one_id_ = id.To<cc::SurfaceId>();
72 } 80 }
73 81
74 void ChildTwoProducedFrame(SurfaceIdPtr id) { 82 void ChildTwoProducedFrame(SurfaceIdPtr id) {
75 child_two_id_ = id.To<cc::SurfaceId>(); 83 child_two_id_ = id.To<cc::SurfaceId>();
76 } 84 }
77 85
78 void Draw(int offset) { 86 void Draw(int offset) {
79 int bounced_offset = offset; 87 int bounced_offset = offset;
80 if (offset > 200) 88 if (offset > 200)
81 bounced_offset = 400 - offset; 89 bounced_offset = 400 - offset;
82 embedder_->ProduceFrame(child_one_id_, child_two_id_, child_size_, size_, 90 if (!embedder_->frame_pending()) {
83 bounced_offset); 91 embedder_->ProduceFrame(child_one_id_, child_two_id_, child_size_, size_,
92 bounced_offset);
93 }
84 base::MessageLoop::current()->PostDelayedTask( 94 base::MessageLoop::current()->PostDelayedTask(
85 FROM_HERE, 95 FROM_HERE,
86 base::Bind( 96 base::Bind(
87 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400), 97 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400),
88 base::TimeDelta::FromMilliseconds(50)); 98 base::TimeDelta::FromMilliseconds(50));
89 } 99 }
90 100
91 private: 101 private:
92 void SetIdNamespace(uint32_t id_namespace) {
93 auto qualified_id = mojo::SurfaceId::New();
94 qualified_id->id_namespace = id_namespace;
95 qualified_id->local = kLocalId;
96 viewport_->SubmittedFrame(qualified_id.Pass());
97 }
98 void OnCreatedNativeViewport(uint64_t native_viewport_id,
99 mojo::ViewportMetricsPtr metrics) {}
100 102
101 ApplicationImpl* app_impl_; 103 ApplicationImpl* app_impl_;
102 SurfacePtr surface_; 104 DisplayPtr display_;
103 uint32_t id_namespace_; 105 uint32_t id_namespace_;
104 SurfaceIdPtr onscreen_id_;
105 scoped_ptr<Embedder> embedder_; 106 scoped_ptr<Embedder> embedder_;
106 ChildPtr child_one_; 107 ChildPtr child_one_;
107 cc::SurfaceId child_one_id_; 108 cc::SurfaceId child_one_id_;
108 ChildPtr child_two_; 109 ChildPtr child_two_;
109 cc::SurfaceId child_two_id_; 110 cc::SurfaceId child_two_id_;
110 gfx::Size size_; 111 gfx::Size size_;
111 gfx::Size child_size_; 112 gfx::Size child_size_;
112 113
113 NativeViewportPtr viewport_; 114 NativeViewportPtr viewport_;
114 115
115 base::WeakPtrFactory<SurfacesApp> weak_factory_; 116 base::WeakPtrFactory<SurfacesApp> weak_factory_;
116 117
117 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); 118 DISALLOW_COPY_AND_ASSIGN(SurfacesApp);
118 }; 119 };
119 120
120 } // namespace examples 121 } // namespace examples
121 } // namespace mojo 122 } // namespace mojo
122 123
123 MojoResult MojoMain(MojoHandle shell_handle) { 124 MojoResult MojoMain(MojoHandle shell_handle) {
124 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); 125 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp);
125 return runner.Run(shell_handle); 126 return runner.Run(shell_handle);
126 } 127 }
OLDNEW
« no previous file with comments | « examples/surfaces_app/embedder.cc ('k') | mojo/services/gpu/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698