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

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

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

Powered by Google App Engine
This is Rietveld 408576698