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

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

Issue 826423008: Use local ids for Surfaces APIs that can only apply to local surfaces (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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/aura/surface_binding.cc » ('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/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;
29
28 class SurfacesApp : public ApplicationDelegate, 30 class SurfacesApp : public ApplicationDelegate,
29 public SurfaceClient, 31 public SurfaceClient,
30 public NativeViewportClient { 32 public NativeViewportClient {
31 public: 33 public:
32 SurfacesApp() : onscreen_id_(SurfaceId::New()), weak_factory_(this) {} 34 SurfacesApp() : id_namespace_(0u), weak_factory_(this) {}
33 ~SurfacesApp() override {} 35 ~SurfacesApp() override {}
34 36
35 // ApplicationDelegate implementation 37 // ApplicationDelegate implementation
36 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 38 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
37 connection->ConnectToService("mojo:native_viewport_service", &viewport_); 39 connection->ConnectToService("mojo:native_viewport_service", &viewport_);
38 viewport_.set_client(this); 40 viewport_.set_client(this);
39 41
40 connection->ConnectToService("mojo:surfaces_service", &surface_); 42 connection->ConnectToService("mojo:surfaces_service", &surface_);
41 surface_.set_client(this); 43 surface_.set_client(this);
42 embedder_.set_surface(surface_.get()); 44 embedder_.reset(new Embedder(kLocalId, surface_.get()));
43 45
44 size_ = gfx::Size(800, 600); 46 size_ = gfx::Size(800, 600);
45 47
46 viewport_->Create(Size::From(size_), 48 viewport_->Create(Size::From(size_),
47 base::Bind(&SurfacesApp::OnCreatedNativeViewport, 49 base::Bind(&SurfacesApp::OnCreatedNativeViewport,
48 weak_factory_.GetWeakPtr())); 50 weak_factory_.GetWeakPtr()));
49 viewport_->Show(); 51 viewport_->Show();
50 52
51 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2); 53 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2);
52 connection->ConnectToService("mojo:surfaces_child_app", &child_one_); 54 connection->ConnectToService("mojo:surfaces_child_app", &child_one_);
53 connection->ConnectToService("mojo:surfaces_child_gl_app", &child_two_); 55 connection->ConnectToService("mojo:surfaces_child_gl_app", &child_two_);
54 child_one_->ProduceFrame(Color::From(SK_ColorBLUE), 56 child_one_->ProduceFrame(Color::From(SK_ColorBLUE),
55 Size::From(child_size_), 57 Size::From(child_size_),
56 base::Bind(&SurfacesApp::ChildOneProducedFrame, 58 base::Bind(&SurfacesApp::ChildOneProducedFrame,
57 base::Unretained(this))); 59 base::Unretained(this)));
58 child_two_->ProduceFrame(Color::From(SK_ColorGREEN), 60 child_two_->ProduceFrame(Color::From(SK_ColorGREEN),
59 Size::From(child_size_), 61 Size::From(child_size_),
60 base::Bind(&SurfacesApp::ChildTwoProducedFrame, 62 base::Bind(&SurfacesApp::ChildTwoProducedFrame,
61 base::Unretained(this))); 63 base::Unretained(this)));
64 surface_->CreateSurface(kLocalId);
65 Draw(10);
62 return true; 66 return true;
63 } 67 }
64 68
65 void ChildOneProducedFrame(SurfaceIdPtr id) { 69 void ChildOneProducedFrame(SurfaceIdPtr id) {
66 child_one_id_ = id.To<cc::SurfaceId>(); 70 child_one_id_ = id.To<cc::SurfaceId>();
67 } 71 }
68 72
69 void ChildTwoProducedFrame(SurfaceIdPtr id) { 73 void ChildTwoProducedFrame(SurfaceIdPtr id) {
70 child_two_id_ = id.To<cc::SurfaceId>(); 74 child_two_id_ = id.To<cc::SurfaceId>();
71 } 75 }
72 76
73 void Draw(int offset) { 77 void Draw(int offset) {
74 int bounced_offset = offset; 78 int bounced_offset = offset;
75 if (offset > 200) 79 if (offset > 200)
76 bounced_offset = 400 - offset; 80 bounced_offset = 400 - offset;
77 embedder_.ProduceFrame(child_one_id_, child_two_id_, child_size_, size_, 81 embedder_->ProduceFrame(child_one_id_, child_two_id_, child_size_, size_,
78 bounced_offset); 82 bounced_offset);
79 base::MessageLoop::current()->PostDelayedTask( 83 base::MessageLoop::current()->PostDelayedTask(
80 FROM_HERE, 84 FROM_HERE,
81 base::Bind( 85 base::Bind(
82 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400), 86 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400),
83 base::TimeDelta::FromMilliseconds(50)); 87 base::TimeDelta::FromMilliseconds(50));
84 } 88 }
85 89
86 // SurfaceClient implementation. 90 // SurfaceClient implementation.
87 void SetIdNamespace(uint32_t id_namespace) override { 91 void SetIdNamespace(uint32_t id_namespace) override {
88 onscreen_id_->id_namespace = id_namespace; 92 auto qualified_id = mojo::SurfaceId::New();
89 embedder_.set_surface_id(onscreen_id_.Clone()); 93 qualified_id->id_namespace = id_namespace;
90 surface_->CreateSurface(onscreen_id_.Clone()); 94 qualified_id->local = kLocalId;
91 viewport_->SubmittedFrame(onscreen_id_.Clone()); 95 viewport_->SubmittedFrame(qualified_id.Pass());
92 Draw(10);
93 } 96 }
94 void ReturnResources(Array<ReturnedResourcePtr> resources) override { 97 void ReturnResources(Array<ReturnedResourcePtr> resources) override {
95 DCHECK(!resources.size()); 98 DCHECK(!resources.size());
96 } 99 }
97 // NativeViewportClient implementation. 100 // NativeViewportClient implementation.
98 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override {} 101 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override {}
99 void OnDestroyed() override {} 102 void OnDestroyed() override {}
100 103
101 private: 104 private:
102 void OnCreatedNativeViewport(uint64_t native_viewport_id) {} 105 void OnCreatedNativeViewport(uint64_t native_viewport_id) {}
103 106
104 SurfacePtr surface_; 107 SurfacePtr surface_;
108 uint32_t id_namespace_;
105 SurfaceIdPtr onscreen_id_; 109 SurfaceIdPtr onscreen_id_;
106 Embedder embedder_; 110 scoped_ptr<Embedder> embedder_;
107 ChildPtr child_one_; 111 ChildPtr child_one_;
108 cc::SurfaceId child_one_id_; 112 cc::SurfaceId child_one_id_;
109 ChildPtr child_two_; 113 ChildPtr child_two_;
110 cc::SurfaceId child_two_id_; 114 cc::SurfaceId child_two_id_;
111 gfx::Size size_; 115 gfx::Size size_;
112 gfx::Size child_size_; 116 gfx::Size child_size_;
113 117
114 NativeViewportPtr viewport_; 118 NativeViewportPtr viewport_;
115 119
116 base::WeakPtrFactory<SurfacesApp> weak_factory_; 120 base::WeakPtrFactory<SurfacesApp> weak_factory_;
117 121
118 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); 122 DISALLOW_COPY_AND_ASSIGN(SurfacesApp);
119 }; 123 };
120 124
121 } // namespace examples 125 } // namespace examples
122 } // namespace mojo 126 } // namespace mojo
123 127
124 MojoResult MojoMain(MojoHandle shell_handle) { 128 MojoResult MojoMain(MojoHandle shell_handle) {
125 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); 129 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp);
126 return runner.Run(shell_handle); 130 return runner.Run(shell_handle);
127 } 131 }
OLDNEW
« no previous file with comments | « examples/surfaces_app/embedder.cc ('k') | mojo/aura/surface_binding.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698