OLD | NEW |
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 "services/fake_surfaces/fake_surfaces_service_application.h" | 5 #include "services/fake_surfaces/fake_surfaces_service_application.h" |
6 | 6 |
7 #include "mojo/application/application_runner_chromium.h" | 7 #include "mojo/application/application_runner_chromium.h" |
8 #include "mojo/public/c/system/main.h" | 8 #include "mojo/public/c/system/main.h" |
9 #include "mojo/public/cpp/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
10 #include "mojo/public/cpp/bindings/strong_binding.h" | 10 #include "mojo/public/cpp/bindings/strong_binding.h" |
11 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" | 11 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" |
12 | 12 |
| 13 using mojo::ApplicationConnection; |
| 14 using mojo::Display; |
| 15 using mojo::DisplayFactory; |
13 using mojo::InterfaceRequest; | 16 using mojo::InterfaceRequest; |
| 17 using mojo::ResourceReturnerPtr; |
| 18 using mojo::StrongBinding; |
| 19 using mojo::Surface; |
14 | 20 |
15 namespace fake_surfaces { | 21 namespace fake_surfaces { |
16 | 22 |
17 class FakeSurfaceImpl : public mojo::Surface { | 23 namespace { |
| 24 void ReturnAll(const mojo::Array<mojo::TransferableResourcePtr>& resources, |
| 25 mojo::ResourceReturner* returner) { |
| 26 mojo::Array<mojo::ReturnedResourcePtr> returned; |
| 27 returned.resize(resources.size()); |
| 28 for (size_t i = 0; i < resources.size(); ++i) { |
| 29 auto ret = mojo::ReturnedResource::New(); |
| 30 ret->id = resources[i]->id; |
| 31 ret->sync_point = 0u; |
| 32 ret->count = 1; |
| 33 ret->lost = false; |
| 34 returned[i] = ret.Pass(); |
| 35 } |
| 36 returner->ReturnResources(returned.Pass()); |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
| 41 class FakeDisplayImpl : public Display { |
18 public: | 42 public: |
19 FakeSurfaceImpl(uint32_t id_namespace, | 43 FakeDisplayImpl(ResourceReturnerPtr returner, |
20 mojo::InterfaceRequest<mojo::Surface> request) | 44 InterfaceRequest<Display> request) |
| 45 : returner_(returner.Pass()), binding_(this, request.Pass()) {} |
| 46 ~FakeDisplayImpl() override {} |
| 47 |
| 48 private: |
| 49 // Display implementation |
| 50 void SubmitFrame(mojo::FramePtr frame, |
| 51 const SubmitFrameCallback& callback) override { |
| 52 callback.Run(); |
| 53 if (frame->resources.size() == 0u || !returner_) |
| 54 return; |
| 55 ReturnAll(frame->resources, returner_.get()); |
| 56 } |
| 57 |
| 58 ResourceReturnerPtr returner_; |
| 59 StrongBinding<Display> binding_; |
| 60 }; |
| 61 |
| 62 class FakeDisplayFactoryImpl : public DisplayFactory { |
| 63 public: |
| 64 explicit FakeDisplayFactoryImpl(InterfaceRequest<DisplayFactory> request) |
| 65 : binding_(this, request.Pass()) {} |
| 66 ~FakeDisplayFactoryImpl() override {} |
| 67 |
| 68 private: |
| 69 // DisplayFactory implementation. |
| 70 void Create(mojo::ContextProviderPtr context_provider, |
| 71 ResourceReturnerPtr returner, |
| 72 InterfaceRequest<Display> request) override { |
| 73 new FakeDisplayImpl(returner.Pass(), request.Pass()); |
| 74 } |
| 75 |
| 76 StrongBinding<DisplayFactory> binding_; |
| 77 }; |
| 78 |
| 79 class FakeSurfaceImpl : public Surface { |
| 80 public: |
| 81 FakeSurfaceImpl(uint32_t id_namespace, InterfaceRequest<Surface> request) |
21 : id_namespace_(id_namespace), binding_(this, request.Pass()) {} | 82 : id_namespace_(id_namespace), binding_(this, request.Pass()) {} |
22 ~FakeSurfaceImpl() override {} | 83 ~FakeSurfaceImpl() override {} |
23 | 84 |
24 // mojo::Surface implementation. | 85 // Surface implementation. |
25 void GetIdNamespace( | 86 void GetIdNamespace( |
26 const Surface::GetIdNamespaceCallback& callback) override { | 87 const Surface::GetIdNamespaceCallback& callback) override { |
27 callback.Run(id_namespace_); | 88 callback.Run(id_namespace_); |
28 } | 89 } |
29 | 90 |
30 void SetResourceReturner(mojo::ResourceReturnerPtr returner) override { | 91 void SetResourceReturner(ResourceReturnerPtr returner) override { |
31 returner_ = returner.Pass(); | 92 returner_ = returner.Pass(); |
32 } | 93 } |
33 | 94 |
34 void CreateSurface(uint32_t local_id) override {} | 95 void CreateSurface(uint32_t local_id) override {} |
35 | 96 |
36 void SubmitFrame(uint32_t local_id, | 97 void SubmitFrame(uint32_t local_id, |
37 mojo::FramePtr frame, | 98 mojo::FramePtr frame, |
38 const mojo::Closure& callback) override { | 99 const SubmitFrameCallback& callback) override { |
39 callback.Run(); | 100 callback.Run(); |
40 if (frame->resources.size() == 0u || !returner_) | 101 if (frame->resources.size() == 0u || !returner_) |
41 return; | 102 return; |
42 mojo::Array<mojo::ReturnedResourcePtr> returned; | 103 ReturnAll(frame->resources, returner_.get()); |
43 returned.resize(frame->resources.size()); | |
44 for (size_t i = 0; i < frame->resources.size(); ++i) { | |
45 auto ret = mojo::ReturnedResource::New(); | |
46 ret->id = frame->resources[i]->id; | |
47 ret->sync_point = 0u; | |
48 ret->count = 1; | |
49 ret->lost = false; | |
50 returned[i] = ret.Pass(); | |
51 } | |
52 returner_->ReturnResources(returned.Pass()); | |
53 } | 104 } |
54 | 105 |
55 void DestroySurface(uint32_t local_id) override {} | 106 void DestroySurface(uint32_t local_id) override {} |
56 | 107 |
57 void CreateGLES2BoundSurface( | |
58 mojo::CommandBufferPtr gles2_client, | |
59 uint32_t local_id, | |
60 mojo::SizePtr size, | |
61 mojo::InterfaceRequest<mojo::ViewportParameterListener> listener_request) | |
62 override {} | |
63 | |
64 private: | 108 private: |
65 const uint32_t id_namespace_; | 109 const uint32_t id_namespace_; |
66 mojo::ResourceReturnerPtr returner_; | 110 ResourceReturnerPtr returner_; |
67 mojo::StrongBinding<mojo::Surface> binding_; | 111 StrongBinding<Surface> binding_; |
68 | 112 |
69 DISALLOW_COPY_AND_ASSIGN(FakeSurfaceImpl); | 113 DISALLOW_COPY_AND_ASSIGN(FakeSurfaceImpl); |
70 }; | 114 }; |
71 | 115 |
72 FakeSurfacesServiceApplication::FakeSurfacesServiceApplication() | 116 FakeSurfacesServiceApplication::FakeSurfacesServiceApplication() |
73 : next_id_namespace_(1u) { | 117 : next_id_namespace_(1u) { |
74 } | 118 } |
75 | 119 |
76 FakeSurfacesServiceApplication::~FakeSurfacesServiceApplication() { | 120 FakeSurfacesServiceApplication::~FakeSurfacesServiceApplication() { |
77 } | 121 } |
78 | 122 |
79 void FakeSurfacesServiceApplication::Initialize(mojo::ApplicationImpl* app) { | 123 void FakeSurfacesServiceApplication::Initialize(mojo::ApplicationImpl* app) { |
80 tracing_.Initialize(app); | 124 tracing_.Initialize(app); |
81 } | 125 } |
82 | 126 |
83 bool FakeSurfacesServiceApplication::ConfigureIncomingConnection( | 127 bool FakeSurfacesServiceApplication::ConfigureIncomingConnection( |
84 mojo::ApplicationConnection* connection) { | 128 ApplicationConnection* connection) { |
85 connection->AddService(this); | 129 connection->AddService<DisplayFactory>(this); |
| 130 connection->AddService<Surface>(this); |
86 return true; | 131 return true; |
87 } | 132 } |
88 | 133 |
89 void FakeSurfacesServiceApplication::Create( | 134 void FakeSurfacesServiceApplication::Create( |
90 mojo::ApplicationConnection* connection, | 135 ApplicationConnection* connection, |
91 InterfaceRequest<mojo::Surface> request) { | 136 InterfaceRequest<DisplayFactory> request) { |
| 137 new FakeDisplayFactoryImpl(request.Pass()); |
| 138 } |
| 139 |
| 140 void FakeSurfacesServiceApplication::Create(ApplicationConnection* connection, |
| 141 InterfaceRequest<Surface> request) { |
92 new FakeSurfaceImpl(next_id_namespace_++, request.Pass()); | 142 new FakeSurfaceImpl(next_id_namespace_++, request.Pass()); |
93 } | 143 } |
94 | 144 |
95 } // namespace fake_surfaces | 145 } // namespace fake_surfaces |
96 | 146 |
97 MojoResult MojoMain(MojoHandle shell_handle) { | 147 MojoResult MojoMain(MojoHandle shell_handle) { |
98 mojo::ApplicationRunnerChromium runner( | 148 mojo::ApplicationRunnerChromium runner( |
99 new fake_surfaces::FakeSurfacesServiceApplication); | 149 new fake_surfaces::FakeSurfacesServiceApplication); |
100 return runner.Run(shell_handle); | 150 return runner.Run(shell_handle); |
101 } | 151 } |
OLD | NEW |