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

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

Issue 871373015: De-Client Surface interface (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
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/system/core.h" 18 #include "mojo/public/cpp/system/core.h"
19 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h" 19 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h"
20 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" 20 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h"
21 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom. h" 21 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom. h"
22 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" 22 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h"
23 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
24 24
25 namespace mojo { 25 namespace mojo {
26 namespace examples { 26 namespace examples {
27 27
28 static const uint32_t kLocalId = 1u; 28 static const uint32_t kLocalId = 1u;
29 29
30 class SurfacesApp : public ApplicationDelegate, public SurfaceClient { 30 class SurfacesApp : public ApplicationDelegate {
31 public: 31 public:
32 SurfacesApp() : id_namespace_(0u), weak_factory_(this) {} 32 SurfacesApp() : id_namespace_(0u), weak_factory_(this) {}
33 ~SurfacesApp() override {} 33 ~SurfacesApp() override {}
34 34
35 // ApplicationDelegate implementation 35 // ApplicationDelegate implementation
36 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 36 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
37 connection->ConnectToService("mojo:native_viewport_service", &viewport_); 37 connection->ConnectToService("mojo:native_viewport_service", &viewport_);
38 38
39 connection->ConnectToService("mojo:surfaces_service", &surface_); 39 connection->ConnectToService("mojo:surfaces_service", &surface_);
40 surface_.set_client(this); 40 surface_->GetIdNamespace(
41 base::Bind(&SurfacesApp::SetIdNamespace, base::Unretained(this)));
41 embedder_.reset(new Embedder(kLocalId, surface_.get())); 42 embedder_.reset(new Embedder(kLocalId, surface_.get()));
42 43
43 size_ = gfx::Size(800, 600); 44 size_ = gfx::Size(800, 600);
44 45
45 viewport_->Create(Size::From(size_), 46 viewport_->Create(Size::From(size_),
46 base::Bind(&SurfacesApp::OnCreatedNativeViewport, 47 base::Bind(&SurfacesApp::OnCreatedNativeViewport,
47 weak_factory_.GetWeakPtr())); 48 weak_factory_.GetWeakPtr()));
48 viewport_->Show(); 49 viewport_->Show();
49 50
50 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2); 51 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2);
(...skipping 27 matching lines...) Expand all
78 embedder_->ProduceFrame(child_one_id_, child_two_id_, child_size_, size_, 79 embedder_->ProduceFrame(child_one_id_, child_two_id_, child_size_, size_,
79 bounced_offset); 80 bounced_offset);
80 base::MessageLoop::current()->PostDelayedTask( 81 base::MessageLoop::current()->PostDelayedTask(
81 FROM_HERE, 82 FROM_HERE,
82 base::Bind( 83 base::Bind(
83 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400), 84 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400),
84 base::TimeDelta::FromMilliseconds(50)); 85 base::TimeDelta::FromMilliseconds(50));
85 } 86 }
86 87
87 private: 88 private:
88 // SurfaceClient implementation. 89 void SetIdNamespace(uint32_t id_namespace) {
89 void SetIdNamespace(uint32_t id_namespace) override {
90 auto qualified_id = mojo::SurfaceId::New(); 90 auto qualified_id = mojo::SurfaceId::New();
91 qualified_id->id_namespace = id_namespace; 91 qualified_id->id_namespace = id_namespace;
92 qualified_id->local = kLocalId; 92 qualified_id->local = kLocalId;
93 viewport_->SubmittedFrame(qualified_id.Pass()); 93 viewport_->SubmittedFrame(qualified_id.Pass());
94 } 94 }
95 void ReturnResources(Array<ReturnedResourcePtr> resources) override {
96 DCHECK(!resources.size());
97 }
98 void OnCreatedNativeViewport(uint64_t native_viewport_id, 95 void OnCreatedNativeViewport(uint64_t native_viewport_id,
99 mojo::ViewportMetricsPtr metrics) {} 96 mojo::ViewportMetricsPtr metrics) {}
100 97
101 SurfacePtr surface_; 98 SurfacePtr surface_;
102 uint32_t id_namespace_; 99 uint32_t id_namespace_;
103 SurfaceIdPtr onscreen_id_; 100 SurfaceIdPtr onscreen_id_;
104 scoped_ptr<Embedder> embedder_; 101 scoped_ptr<Embedder> embedder_;
105 ChildPtr child_one_; 102 ChildPtr child_one_;
106 cc::SurfaceId child_one_id_; 103 cc::SurfaceId child_one_id_;
107 ChildPtr child_two_; 104 ChildPtr child_two_;
108 cc::SurfaceId child_two_id_; 105 cc::SurfaceId child_two_id_;
109 gfx::Size size_; 106 gfx::Size size_;
110 gfx::Size child_size_; 107 gfx::Size child_size_;
111 108
112 NativeViewportPtr viewport_; 109 NativeViewportPtr viewport_;
113 110
114 base::WeakPtrFactory<SurfacesApp> weak_factory_; 111 base::WeakPtrFactory<SurfacesApp> weak_factory_;
115 112
116 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); 113 DISALLOW_COPY_AND_ASSIGN(SurfacesApp);
117 }; 114 };
118 115
119 } // namespace examples 116 } // namespace examples
120 } // namespace mojo 117 } // namespace mojo
121 118
122 MojoResult MojoMain(MojoHandle shell_handle) { 119 MojoResult MojoMain(MojoHandle shell_handle) {
123 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); 120 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp);
124 return runner.Run(shell_handle); 121 return runner.Run(shell_handle);
125 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698