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 library gpu_mojom; | 5 library audio_server_mojom; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:mojo/bindings.dart' as bindings; | 9 import 'package:mojo/bindings.dart' as bindings; |
10 import 'package:mojo/core.dart' as core; | 10 import 'package:mojo/core.dart' as core; |
11 import 'package:mojo_services/mojo/command_buffer.mojom.dart' as command_buffer_
mojom; | 11 import 'package:mojo_services/mojo/media/audio_track.mojom.dart' as audio_track_
mojom; |
12 | 12 |
13 | 13 |
14 | 14 |
15 class _GpuCreateOffscreenGles2ContextParams extends bindings.Struct { | 15 class _AudioServerCreateTrackParams extends bindings.Struct { |
16 static const List<bindings.StructDataHeader> kVersions = const [ | 16 static const List<bindings.StructDataHeader> kVersions = const [ |
17 const bindings.StructDataHeader(16, 0) | 17 const bindings.StructDataHeader(16, 0) |
18 ]; | 18 ]; |
19 Object gles2Client = null; | 19 Object track = null; |
20 | 20 |
21 _GpuCreateOffscreenGles2ContextParams() : super(kVersions.last.size); | 21 _AudioServerCreateTrackParams() : super(kVersions.last.size); |
22 | 22 |
23 static _GpuCreateOffscreenGles2ContextParams deserialize(bindings.Message mess
age) { | 23 static _AudioServerCreateTrackParams deserialize(bindings.Message message) { |
24 var decoder = new bindings.Decoder(message); | 24 var decoder = new bindings.Decoder(message); |
25 var result = decode(decoder); | 25 var result = decode(decoder); |
26 if (decoder.excessHandles != null) { | 26 if (decoder.excessHandles != null) { |
27 decoder.excessHandles.forEach((h) => h.close()); | 27 decoder.excessHandles.forEach((h) => h.close()); |
28 } | 28 } |
29 return result; | 29 return result; |
30 } | 30 } |
31 | 31 |
32 static _GpuCreateOffscreenGles2ContextParams decode(bindings.Decoder decoder0)
{ | 32 static _AudioServerCreateTrackParams decode(bindings.Decoder decoder0) { |
33 if (decoder0 == null) { | 33 if (decoder0 == null) { |
34 return null; | 34 return null; |
35 } | 35 } |
36 _GpuCreateOffscreenGles2ContextParams result = new _GpuCreateOffscreenGles2C
ontextParams(); | 36 _AudioServerCreateTrackParams result = new _AudioServerCreateTrackParams(); |
37 | 37 |
38 var mainDataHeader = decoder0.decodeStructDataHeader(); | 38 var mainDataHeader = decoder0.decodeStructDataHeader(); |
39 if (mainDataHeader.version <= kVersions.last.version) { | 39 if (mainDataHeader.version <= kVersions.last.version) { |
40 // Scan in reverse order to optimize for more recent versions. | 40 // Scan in reverse order to optimize for more recent versions. |
41 for (int i = kVersions.length - 1; i >= 0; --i) { | 41 for (int i = kVersions.length - 1; i >= 0; --i) { |
42 if (mainDataHeader.version >= kVersions[i].version) { | 42 if (mainDataHeader.version >= kVersions[i].version) { |
43 if (mainDataHeader.size == kVersions[i].size) { | 43 if (mainDataHeader.size == kVersions[i].size) { |
44 // Found a match. | 44 // Found a match. |
45 break; | 45 break; |
46 } | 46 } |
47 throw new bindings.MojoCodecError( | 47 throw new bindings.MojoCodecError( |
48 'Header size doesn\'t correspond to known version size.'); | 48 'Header size doesn\'t correspond to known version size.'); |
49 } | 49 } |
50 } | 50 } |
51 } else if (mainDataHeader.size < kVersions.last.size) { | 51 } else if (mainDataHeader.size < kVersions.last.size) { |
52 throw new bindings.MojoCodecError( | 52 throw new bindings.MojoCodecError( |
53 'Message newer than the last known version cannot be shorter than ' | 53 'Message newer than the last known version cannot be shorter than ' |
54 'required by the last known version.'); | 54 'required by the last known version.'); |
55 } | 55 } |
56 if (mainDataHeader.version >= 0) { | 56 if (mainDataHeader.version >= 0) { |
57 | 57 |
58 result.gles2Client = decoder0.decodeInterfaceRequest(8, false, command_buf
fer_mojom.CommandBufferStub.newFromEndpoint); | 58 result.track = decoder0.decodeInterfaceRequest(8, false, audio_track_mojom
.AudioTrackStub.newFromEndpoint); |
59 } | 59 } |
60 return result; | 60 return result; |
61 } | 61 } |
62 | 62 |
63 void encode(bindings.Encoder encoder) { | 63 void encode(bindings.Encoder encoder) { |
64 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); | 64 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
65 | 65 |
66 encoder0.encodeInterfaceRequest(gles2Client, 8, false); | 66 encoder0.encodeInterfaceRequest(track, 8, false); |
67 } | 67 } |
68 | 68 |
69 String toString() { | 69 String toString() { |
70 return "_GpuCreateOffscreenGles2ContextParams(" | 70 return "_AudioServerCreateTrackParams(" |
71 "gles2Client: $gles2Client" ")"; | 71 "track: $track" ")"; |
72 } | 72 } |
73 | 73 |
74 Map toJson() { | 74 Map toJson() { |
75 throw new bindings.MojoCodecError( | 75 throw new bindings.MojoCodecError( |
76 'Object containing handles cannot be encoded to JSON.'); | 76 'Object containing handles cannot be encoded to JSON.'); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 const int _Gpu_createOffscreenGles2ContextName = 0; | 80 const int _AudioServer_createTrackName = 0; |
81 | 81 |
82 abstract class Gpu { | 82 abstract class AudioServer { |
83 static const String serviceName = "mojo::Gpu"; | 83 static const String serviceName = "mojo::media::AudioServer"; |
84 void createOffscreenGles2Context(Object gles2Client); | 84 void createTrack(Object track); |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 class _GpuProxyImpl extends bindings.Proxy { | 88 class _AudioServerProxyImpl extends bindings.Proxy { |
89 _GpuProxyImpl.fromEndpoint( | 89 _AudioServerProxyImpl.fromEndpoint( |
90 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 90 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
91 | 91 |
92 _GpuProxyImpl.fromHandle(core.MojoHandle handle) : | 92 _AudioServerProxyImpl.fromHandle(core.MojoHandle handle) : |
93 super.fromHandle(handle); | 93 super.fromHandle(handle); |
94 | 94 |
95 _GpuProxyImpl.unbound() : super.unbound(); | 95 _AudioServerProxyImpl.unbound() : super.unbound(); |
96 | 96 |
97 static _GpuProxyImpl newFromEndpoint( | 97 static _AudioServerProxyImpl newFromEndpoint( |
98 core.MojoMessagePipeEndpoint endpoint) { | 98 core.MojoMessagePipeEndpoint endpoint) { |
99 assert(endpoint.setDescription("For _GpuProxyImpl")); | 99 assert(endpoint.setDescription("For _AudioServerProxyImpl")); |
100 return new _GpuProxyImpl.fromEndpoint(endpoint); | 100 return new _AudioServerProxyImpl.fromEndpoint(endpoint); |
101 } | 101 } |
102 | 102 |
103 void handleResponse(bindings.ServiceMessage message) { | 103 void handleResponse(bindings.ServiceMessage message) { |
104 switch (message.header.type) { | 104 switch (message.header.type) { |
105 default: | 105 default: |
106 proxyError("Unexpected message type: ${message.header.type}"); | 106 proxyError("Unexpected message type: ${message.header.type}"); |
107 close(immediate: true); | 107 close(immediate: true); |
108 break; | 108 break; |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 String toString() { | 112 String toString() { |
113 var superString = super.toString(); | 113 var superString = super.toString(); |
114 return "_GpuProxyImpl($superString)"; | 114 return "_AudioServerProxyImpl($superString)"; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 | 118 |
119 class _GpuProxyCalls implements Gpu { | 119 class _AudioServerProxyCalls implements AudioServer { |
120 _GpuProxyImpl _proxyImpl; | 120 _AudioServerProxyImpl _proxyImpl; |
121 | 121 |
122 _GpuProxyCalls(this._proxyImpl); | 122 _AudioServerProxyCalls(this._proxyImpl); |
123 void createOffscreenGles2Context(Object gles2Client) { | 123 void createTrack(Object track) { |
124 if (!_proxyImpl.isBound) { | 124 if (!_proxyImpl.isBound) { |
125 _proxyImpl.proxyError("The Proxy is closed."); | 125 _proxyImpl.proxyError("The Proxy is closed."); |
126 return; | 126 return; |
127 } | 127 } |
128 var params = new _GpuCreateOffscreenGles2ContextParams(); | 128 var params = new _AudioServerCreateTrackParams(); |
129 params.gles2Client = gles2Client; | 129 params.track = track; |
130 _proxyImpl.sendMessage(params, _Gpu_createOffscreenGles2ContextName); | 130 _proxyImpl.sendMessage(params, _AudioServer_createTrackName); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 | 134 |
135 class GpuProxy implements bindings.ProxyBase { | 135 class AudioServerProxy implements bindings.ProxyBase { |
136 final bindings.Proxy impl; | 136 final bindings.Proxy impl; |
137 Gpu ptr; | 137 AudioServer ptr; |
138 | 138 |
139 GpuProxy(_GpuProxyImpl proxyImpl) : | 139 AudioServerProxy(_AudioServerProxyImpl proxyImpl) : |
140 impl = proxyImpl, | 140 impl = proxyImpl, |
141 ptr = new _GpuProxyCalls(proxyImpl); | 141 ptr = new _AudioServerProxyCalls(proxyImpl); |
142 | 142 |
143 GpuProxy.fromEndpoint( | 143 AudioServerProxy.fromEndpoint( |
144 core.MojoMessagePipeEndpoint endpoint) : | 144 core.MojoMessagePipeEndpoint endpoint) : |
145 impl = new _GpuProxyImpl.fromEndpoint(endpoint) { | 145 impl = new _AudioServerProxyImpl.fromEndpoint(endpoint) { |
146 ptr = new _GpuProxyCalls(impl); | 146 ptr = new _AudioServerProxyCalls(impl); |
147 } | 147 } |
148 | 148 |
149 GpuProxy.fromHandle(core.MojoHandle handle) : | 149 AudioServerProxy.fromHandle(core.MojoHandle handle) : |
150 impl = new _GpuProxyImpl.fromHandle(handle) { | 150 impl = new _AudioServerProxyImpl.fromHandle(handle) { |
151 ptr = new _GpuProxyCalls(impl); | 151 ptr = new _AudioServerProxyCalls(impl); |
152 } | 152 } |
153 | 153 |
154 GpuProxy.unbound() : | 154 AudioServerProxy.unbound() : |
155 impl = new _GpuProxyImpl.unbound() { | 155 impl = new _AudioServerProxyImpl.unbound() { |
156 ptr = new _GpuProxyCalls(impl); | 156 ptr = new _AudioServerProxyCalls(impl); |
157 } | 157 } |
158 | 158 |
159 factory GpuProxy.connectToService( | 159 factory AudioServerProxy.connectToService( |
160 bindings.ServiceConnector s, String url, [String serviceName]) { | 160 bindings.ServiceConnector s, String url, [String serviceName]) { |
161 GpuProxy p = new GpuProxy.unbound(); | 161 AudioServerProxy p = new AudioServerProxy.unbound(); |
162 s.connectToService(url, p, serviceName); | 162 s.connectToService(url, p, serviceName); |
163 return p; | 163 return p; |
164 } | 164 } |
165 | 165 |
166 static GpuProxy newFromEndpoint( | 166 static AudioServerProxy newFromEndpoint( |
167 core.MojoMessagePipeEndpoint endpoint) { | 167 core.MojoMessagePipeEndpoint endpoint) { |
168 assert(endpoint.setDescription("For GpuProxy")); | 168 assert(endpoint.setDescription("For AudioServerProxy")); |
169 return new GpuProxy.fromEndpoint(endpoint); | 169 return new AudioServerProxy.fromEndpoint(endpoint); |
170 } | 170 } |
171 | 171 |
172 String get serviceName => Gpu.serviceName; | 172 String get serviceName => AudioServer.serviceName; |
173 | 173 |
174 Future close({bool immediate: false}) => impl.close(immediate: immediate); | 174 Future close({bool immediate: false}) => impl.close(immediate: immediate); |
175 | 175 |
176 Future responseOrError(Future f) => impl.responseOrError(f); | 176 Future responseOrError(Future f) => impl.responseOrError(f); |
177 | 177 |
178 Future get errorFuture => impl.errorFuture; | 178 Future get errorFuture => impl.errorFuture; |
179 | 179 |
180 int get version => impl.version; | 180 int get version => impl.version; |
181 | 181 |
182 Future<int> queryVersion() => impl.queryVersion(); | 182 Future<int> queryVersion() => impl.queryVersion(); |
183 | 183 |
184 void requireVersion(int requiredVersion) { | 184 void requireVersion(int requiredVersion) { |
185 impl.requireVersion(requiredVersion); | 185 impl.requireVersion(requiredVersion); |
186 } | 186 } |
187 | 187 |
188 String toString() { | 188 String toString() { |
189 return "GpuProxy($impl)"; | 189 return "AudioServerProxy($impl)"; |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 | 193 |
194 class GpuStub extends bindings.Stub { | 194 class AudioServerStub extends bindings.Stub { |
195 Gpu _impl = null; | 195 AudioServer _impl = null; |
196 | 196 |
197 GpuStub.fromEndpoint( | 197 AudioServerStub.fromEndpoint( |
198 core.MojoMessagePipeEndpoint endpoint, [this._impl]) | 198 core.MojoMessagePipeEndpoint endpoint, [this._impl]) |
199 : super.fromEndpoint(endpoint); | 199 : super.fromEndpoint(endpoint); |
200 | 200 |
201 GpuStub.fromHandle(core.MojoHandle handle, [this._impl]) | 201 AudioServerStub.fromHandle(core.MojoHandle handle, [this._impl]) |
202 : super.fromHandle(handle); | 202 : super.fromHandle(handle); |
203 | 203 |
204 GpuStub.unbound() : super.unbound(); | 204 AudioServerStub.unbound() : super.unbound(); |
205 | 205 |
206 static GpuStub newFromEndpoint( | 206 static AudioServerStub newFromEndpoint( |
207 core.MojoMessagePipeEndpoint endpoint) { | 207 core.MojoMessagePipeEndpoint endpoint) { |
208 assert(endpoint.setDescription("For GpuStub")); | 208 assert(endpoint.setDescription("For AudioServerStub")); |
209 return new GpuStub.fromEndpoint(endpoint); | 209 return new AudioServerStub.fromEndpoint(endpoint); |
210 } | 210 } |
211 | 211 |
212 | 212 |
213 | 213 |
214 dynamic handleMessage(bindings.ServiceMessage message) { | 214 dynamic handleMessage(bindings.ServiceMessage message) { |
215 if (bindings.ControlMessageHandler.isControlMessage(message)) { | 215 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
216 return bindings.ControlMessageHandler.handleMessage(this, | 216 return bindings.ControlMessageHandler.handleMessage(this, |
217 0, | 217 0, |
218 message); | 218 message); |
219 } | 219 } |
220 assert(_impl != null); | 220 assert(_impl != null); |
221 switch (message.header.type) { | 221 switch (message.header.type) { |
222 case _Gpu_createOffscreenGles2ContextName: | 222 case _AudioServer_createTrackName: |
223 var params = _GpuCreateOffscreenGles2ContextParams.deserialize( | 223 var params = _AudioServerCreateTrackParams.deserialize( |
224 message.payload); | 224 message.payload); |
225 _impl.createOffscreenGles2Context(params.gles2Client); | 225 _impl.createTrack(params.track); |
226 break; | 226 break; |
227 default: | 227 default: |
228 throw new bindings.MojoCodecError("Unexpected message name"); | 228 throw new bindings.MojoCodecError("Unexpected message name"); |
229 break; | 229 break; |
230 } | 230 } |
231 return null; | 231 return null; |
232 } | 232 } |
233 | 233 |
234 Gpu get impl => _impl; | 234 AudioServer get impl => _impl; |
235 set impl(Gpu d) { | 235 set impl(AudioServer d) { |
236 assert(_impl == null); | 236 assert(_impl == null); |
237 _impl = d; | 237 _impl = d; |
238 } | 238 } |
239 | 239 |
240 String toString() { | 240 String toString() { |
241 var superString = super.toString(); | 241 var superString = super.toString(); |
242 return "GpuStub($superString)"; | 242 return "AudioServerStub($superString)"; |
243 } | 243 } |
244 | 244 |
245 int get version => 0; | 245 int get version => 0; |
246 } | 246 } |
247 | 247 |
248 | 248 |
OLD | NEW |