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/common/tracing_impl.h" | 8 #include "mojo/common/tracing_impl.h" |
9 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.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::InterfaceRequest; | 13 using mojo::InterfaceRequest; |
14 | 14 |
15 namespace fake_surfaces { | 15 namespace fake_surfaces { |
16 | 16 |
17 class FakeSurfaceImpl : public mojo::Surface { | 17 class FakeSurfaceImpl : public mojo::Surface { |
18 public: | 18 public: |
19 FakeSurfaceImpl(uint32_t id_namespace, mojo::SurfacePtr* ptr) | 19 FakeSurfaceImpl(uint32_t id_namespace, |
20 : binding_(this, ptr) { | 20 mojo::InterfaceRequest<mojo::Surface> request) |
| 21 : binding_(this, request.Pass()) { |
21 binding_.client()->SetIdNamespace(id_namespace); | 22 binding_.client()->SetIdNamespace(id_namespace); |
22 } | 23 } |
23 ~FakeSurfaceImpl() override {} | 24 ~FakeSurfaceImpl() override {} |
24 | 25 |
25 // mojo::Surface implementation. | 26 // mojo::Surface implementation. |
26 void CreateSurface(mojo::SurfaceIdPtr id) override {} | 27 void CreateSurface(uint32_t local_id) override {} |
27 | 28 |
28 void SubmitFrame(mojo::SurfaceIdPtr id, | 29 void SubmitFrame(uint32_t local_id, |
29 mojo::FramePtr frame, | 30 mojo::FramePtr frame, |
30 const mojo::Closure& callback) override { | 31 const mojo::Closure& callback) override { |
31 callback.Run(); | 32 callback.Run(); |
32 if (frame->resources.size() == 0u) | 33 if (frame->resources.size() == 0u) |
33 return; | 34 return; |
34 mojo::Array<mojo::ReturnedResourcePtr> returned; | 35 mojo::Array<mojo::ReturnedResourcePtr> returned; |
35 returned.resize(frame->resources.size()); | 36 returned.resize(frame->resources.size()); |
36 for (size_t i = 0; i < frame->resources.size(); ++i) { | 37 for (size_t i = 0; i < frame->resources.size(); ++i) { |
37 auto ret = mojo::ReturnedResource::New(); | 38 auto ret = mojo::ReturnedResource::New(); |
38 ret->id = frame->resources[i]->id; | 39 ret->id = frame->resources[i]->id; |
39 ret->sync_point = 0u; | 40 ret->sync_point = 0u; |
40 ret->count = 1; | 41 ret->count = 1; |
41 ret->lost = false; | 42 ret->lost = false; |
42 returned[i] = ret.Pass(); | 43 returned[i] = ret.Pass(); |
43 } | 44 } |
44 binding_.client()->ReturnResources(returned.Pass()); | 45 binding_.client()->ReturnResources(returned.Pass()); |
45 } | 46 } |
46 | 47 |
47 void DestroySurface(mojo::SurfaceIdPtr id) override {} | 48 void DestroySurface(uint32_t local_id) override {} |
48 | 49 |
49 void CreateGLES2BoundSurface( | 50 void CreateGLES2BoundSurface( |
50 mojo::CommandBufferPtr gles2_client, | 51 mojo::CommandBufferPtr gles2_client, |
51 mojo::SurfaceIdPtr id, | 52 uint32_t local_id, |
52 mojo::SizePtr size, | 53 mojo::SizePtr size, |
53 mojo::InterfaceRequest<mojo::ViewportParameterListener> listener_request) | 54 mojo::InterfaceRequest<mojo::ViewportParameterListener> listener_request) |
54 override { | 55 override {} |
55 } | |
56 | 56 |
57 private: | 57 private: |
58 mojo::StrongBinding<mojo::Surface> binding_; | 58 mojo::StrongBinding<mojo::Surface> binding_; |
59 | 59 |
60 DISALLOW_COPY_AND_ASSIGN(FakeSurfaceImpl); | 60 DISALLOW_COPY_AND_ASSIGN(FakeSurfaceImpl); |
61 }; | 61 }; |
62 | 62 |
63 class FakeSurfacesServiceImpl : public mojo::SurfacesService { | 63 class FakeSurfacesServiceImpl : public mojo::SurfacesService { |
64 public: | 64 public: |
65 FakeSurfacesServiceImpl(uint32_t* id_namespace, | 65 FakeSurfacesServiceImpl(uint32_t* id_namespace, |
66 InterfaceRequest<mojo::SurfacesService> request) | 66 InterfaceRequest<mojo::SurfacesService> request) |
67 : binding_(this, request.Pass()), next_id_namespace_(id_namespace) {} | 67 : binding_(this, request.Pass()), next_id_namespace_(id_namespace) {} |
68 ~FakeSurfacesServiceImpl() override {} | 68 ~FakeSurfacesServiceImpl() override {} |
69 | 69 |
70 // mojo::SurfacesService implementation. | 70 // mojo::SurfacesService implementation. |
71 void CreateSurfaceConnection( | 71 void CreateSurfaceConnection( |
72 const mojo::Callback<void(mojo::SurfacePtr, uint32_t)>& callback) | 72 const mojo::Callback<void(mojo::SurfacePtr, uint32_t)>& callback) |
73 override { | 73 override { |
74 mojo::SurfacePtr surface; | 74 mojo::SurfacePtr surface; |
75 uint32_t id_namespace = (*next_id_namespace_)++; | 75 uint32_t id_namespace = (*next_id_namespace_)++; |
76 new FakeSurfaceImpl(id_namespace, &surface); | 76 new FakeSurfaceImpl(id_namespace, GetProxy(&surface)); |
77 callback.Run(surface.Pass(), id_namespace); | 77 callback.Run(surface.Pass(), id_namespace); |
78 } | 78 } |
79 | 79 |
80 private: | 80 private: |
81 mojo::StrongBinding<mojo::SurfacesService> binding_; | 81 mojo::StrongBinding<mojo::SurfacesService> binding_; |
82 uint32_t* next_id_namespace_; | 82 uint32_t* next_id_namespace_; |
83 | 83 |
84 DISALLOW_COPY_AND_ASSIGN(FakeSurfacesServiceImpl); | 84 DISALLOW_COPY_AND_ASSIGN(FakeSurfacesServiceImpl); |
85 }; | 85 }; |
86 | 86 |
87 FakeSurfacesServiceApplication::FakeSurfacesServiceApplication() | 87 FakeSurfacesServiceApplication::FakeSurfacesServiceApplication() |
88 : next_id_namespace_(1u) { | 88 : next_id_namespace_(1u) { |
89 } | 89 } |
90 | 90 |
91 FakeSurfacesServiceApplication::~FakeSurfacesServiceApplication() { | 91 FakeSurfacesServiceApplication::~FakeSurfacesServiceApplication() { |
92 } | 92 } |
93 | 93 |
94 void FakeSurfacesServiceApplication::Initialize(mojo::ApplicationImpl* app) { | 94 void FakeSurfacesServiceApplication::Initialize(mojo::ApplicationImpl* app) { |
95 mojo::TracingImpl::Create(app); | 95 mojo::TracingImpl::Create(app); |
96 } | 96 } |
97 | 97 |
98 bool FakeSurfacesServiceApplication::ConfigureIncomingConnection( | 98 bool FakeSurfacesServiceApplication::ConfigureIncomingConnection( |
99 mojo::ApplicationConnection* connection) { | 99 mojo::ApplicationConnection* connection) { |
100 connection->AddService(this); | 100 connection->AddService<mojo::SurfacesService>(this); |
| 101 connection->AddService<mojo::Surface>(this); |
101 return true; | 102 return true; |
102 } | 103 } |
103 | 104 |
104 void FakeSurfacesServiceApplication::Create( | 105 void FakeSurfacesServiceApplication::Create( |
105 mojo::ApplicationConnection* connection, | 106 mojo::ApplicationConnection* connection, |
106 InterfaceRequest<mojo::SurfacesService> request) { | 107 InterfaceRequest<mojo::SurfacesService> request) { |
107 new FakeSurfacesServiceImpl(&next_id_namespace_, request.Pass()); | 108 new FakeSurfacesServiceImpl(&next_id_namespace_, request.Pass()); |
108 } | 109 } |
109 | 110 |
| 111 void FakeSurfacesServiceApplication::Create( |
| 112 mojo::ApplicationConnection* connection, |
| 113 InterfaceRequest<mojo::Surface> request) { |
| 114 new FakeSurfaceImpl(next_id_namespace_++, request.Pass()); |
| 115 } |
| 116 |
110 } // namespace fake_surfaces | 117 } // namespace fake_surfaces |
111 | 118 |
112 MojoResult MojoMain(MojoHandle shell_handle) { | 119 MojoResult MojoMain(MojoHandle shell_handle) { |
113 mojo::ApplicationRunnerChromium runner( | 120 mojo::ApplicationRunnerChromium runner( |
114 new fake_surfaces::FakeSurfacesServiceApplication); | 121 new fake_surfaces::FakeSurfacesServiceApplication); |
115 return runner.Run(shell_handle); | 122 return runner.Run(shell_handle); |
116 } | 123 } |
OLD | NEW |