Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <sys/types.h> |
| 19 | |
| 20 | #include <utils/Errors.h> |
| 21 | #include <utils/RefBase.h> |
| 22 | #include <utils/Vector.h> |
| 23 | #include <utils/Timers.h> |
| 24 | |
| 25 | #include <binder/Parcel.h> |
| 26 | #include <binder/IInterface.h> |
| 27 | |
| 28 | #include <gui/ISurfaceTexture.h> |
| 29 | |
| 30 | namespace android { |
| 31 | // ---------------------------------------------------------------------------- |
| 32 | |
| 33 | enum { |
| 34 | REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION, |
| 35 | SET_BUFFER_COUNT, |
| 36 | DEQUEUE_BUFFER, |
| 37 | QUEUE_BUFFER, |
| 38 | CANCEL_BUFFER, |
| 39 | SET_CROP, |
| 40 | SET_TRANSFORM, |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 41 | QUERY, |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 42 | SET_SYNCHRONOUS_MODE, |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 43 | CONNECT, |
| 44 | DISCONNECT, |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 45 | SET_SCALING_MODE, |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | |
| 49 | class BpSurfaceTexture : public BpInterface<ISurfaceTexture> |
| 50 | { |
| 51 | public: |
| 52 | BpSurfaceTexture(const sp<IBinder>& impl) |
| 53 | : BpInterface<ISurfaceTexture>(impl) |
| 54 | { |
| 55 | } |
| 56 | |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 57 | virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 58 | Parcel data, reply; |
| 59 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 60 | data.writeInt32(bufferIdx); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 61 | status_t result =remote()->transact(REQUEST_BUFFER, data, &reply); |
| 62 | if (result != NO_ERROR) { |
| 63 | return result; |
| 64 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 65 | bool nonNull = reply.readInt32(); |
| 66 | if (nonNull) { |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 67 | *buf = new GraphicBuffer(); |
| 68 | reply.read(**buf); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 69 | } |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 70 | result = reply.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 71 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | virtual status_t setBufferCount(int bufferCount) |
| 75 | { |
| 76 | Parcel data, reply; |
| 77 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 78 | data.writeInt32(bufferCount); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 79 | status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply); |
| 80 | if (result != NO_ERROR) { |
| 81 | return result; |
| 82 | } |
| 83 | result = reply.readInt32(); |
| 84 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 87 | virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h, |
| 88 | uint32_t format, uint32_t usage) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 89 | Parcel data, reply; |
| 90 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 91 | data.writeInt32(w); |
| 92 | data.writeInt32(h); |
| 93 | data.writeInt32(format); |
| 94 | data.writeInt32(usage); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 95 | status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); |
| 96 | if (result != NO_ERROR) { |
| 97 | return result; |
| 98 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 99 | *buf = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 100 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 101 | return result; |
| 102 | } |
| 103 | |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 104 | virtual status_t queueBuffer(int buf, int64_t timestamp, |
| 105 | uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 106 | Parcel data, reply; |
| 107 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 108 | data.writeInt32(buf); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 109 | data.writeInt64(timestamp); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 110 | status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); |
| 111 | if (result != NO_ERROR) { |
| 112 | return result; |
| 113 | } |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 114 | *outWidth = reply.readInt32(); |
| 115 | *outHeight = reply.readInt32(); |
| 116 | *outTransform = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 117 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 118 | return result; |
| 119 | } |
| 120 | |
| 121 | virtual void cancelBuffer(int buf) { |
| 122 | Parcel data, reply; |
| 123 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 124 | data.writeInt32(buf); |
| 125 | remote()->transact(CANCEL_BUFFER, data, &reply); |
| 126 | } |
| 127 | |
| 128 | virtual status_t setCrop(const Rect& reg) { |
| 129 | Parcel data, reply; |
| 130 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 131 | data.writeFloat(reg.left); |
| 132 | data.writeFloat(reg.top); |
| 133 | data.writeFloat(reg.right); |
| 134 | data.writeFloat(reg.bottom); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 135 | status_t result = remote()->transact(SET_CROP, data, &reply); |
| 136 | if (result != NO_ERROR) { |
| 137 | return result; |
| 138 | } |
| 139 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 140 | return result; |
| 141 | } |
| 142 | |
| 143 | virtual status_t setTransform(uint32_t transform) { |
| 144 | Parcel data, reply; |
| 145 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 146 | data.writeInt32(transform); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 147 | status_t result = remote()->transact(SET_TRANSFORM, data, &reply); |
| 148 | if (result != NO_ERROR) { |
| 149 | return result; |
| 150 | } |
| 151 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 152 | return result; |
| 153 | } |
Jamie Gennis | 1b20cde | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 154 | |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 155 | virtual status_t setScalingMode(int mode) { |
| 156 | Parcel data, reply; |
| 157 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 158 | data.writeInt32(mode); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 159 | status_t result = remote()->transact(SET_SCALING_MODE, data, &reply); |
| 160 | if (result != NO_ERROR) { |
| 161 | return result; |
| 162 | } |
| 163 | result = reply.readInt32(); |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 164 | return result; |
| 165 | } |
| 166 | |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 167 | virtual int query(int what, int* value) { |
| 168 | Parcel data, reply; |
| 169 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 170 | data.writeInt32(what); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 171 | status_t result = remote()->transact(QUERY, data, &reply); |
| 172 | if (result != NO_ERROR) { |
| 173 | return result; |
| 174 | } |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 175 | value[0] = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 176 | result = reply.readInt32(); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 177 | return result; |
| 178 | } |
| 179 | |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 180 | virtual status_t setSynchronousMode(bool enabled) { |
| 181 | Parcel data, reply; |
| 182 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 183 | data.writeInt32(enabled); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 184 | status_t result = remote()->transact(SET_SYNCHRONOUS_MODE, data, &reply); |
| 185 | if (result != NO_ERROR) { |
| 186 | return result; |
| 187 | } |
| 188 | result = reply.readInt32(); |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 189 | return result; |
| 190 | } |
| 191 | |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 192 | virtual status_t connect(int api, |
| 193 | uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 194 | Parcel data, reply; |
| 195 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 196 | data.writeInt32(api); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 197 | status_t result = remote()->transact(CONNECT, data, &reply); |
| 198 | if (result != NO_ERROR) { |
| 199 | return result; |
| 200 | } |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 201 | *outWidth = reply.readInt32(); |
| 202 | *outHeight = reply.readInt32(); |
| 203 | *outTransform = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 204 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 205 | return result; |
| 206 | } |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 207 | |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 208 | virtual status_t disconnect(int api) { |
| 209 | Parcel data, reply; |
| 210 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 211 | data.writeInt32(api); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 212 | status_t result =remote()->transact(DISCONNECT, data, &reply); |
| 213 | if (result != NO_ERROR) { |
| 214 | return result; |
| 215 | } |
| 216 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 217 | return result; |
| 218 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | IMPLEMENT_META_INTERFACE(SurfaceTexture, "android.gui.SurfaceTexture"); |
| 222 | |
| 223 | // ---------------------------------------------------------------------- |
| 224 | |
| 225 | status_t BnSurfaceTexture::onTransact( |
| 226 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 227 | { |
| 228 | switch(code) { |
| 229 | case REQUEST_BUFFER: { |
| 230 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 231 | int bufferIdx = data.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 232 | sp<GraphicBuffer> buffer; |
| 233 | int result = requestBuffer(bufferIdx, &buffer); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 234 | reply->writeInt32(buffer != 0); |
| 235 | if (buffer != 0) { |
| 236 | reply->write(*buffer); |
| 237 | } |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 238 | reply->writeInt32(result); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 239 | return NO_ERROR; |
| 240 | } break; |
| 241 | case SET_BUFFER_COUNT: { |
| 242 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 243 | int bufferCount = data.readInt32(); |
| 244 | int result = setBufferCount(bufferCount); |
| 245 | reply->writeInt32(result); |
| 246 | return NO_ERROR; |
| 247 | } break; |
| 248 | case DEQUEUE_BUFFER: { |
| 249 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 250 | uint32_t w = data.readInt32(); |
| 251 | uint32_t h = data.readInt32(); |
| 252 | uint32_t format = data.readInt32(); |
| 253 | uint32_t usage = data.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 254 | int buf; |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 255 | int result = dequeueBuffer(&buf, w, h, format, usage); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 256 | reply->writeInt32(buf); |
| 257 | reply->writeInt32(result); |
| 258 | return NO_ERROR; |
| 259 | } break; |
| 260 | case QUEUE_BUFFER: { |
| 261 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 262 | int buf = data.readInt32(); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 263 | int64_t timestamp = data.readInt64(); |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 264 | uint32_t outWidth, outHeight, outTransform; |
| 265 | status_t result = queueBuffer(buf, timestamp, |
| 266 | &outWidth, &outHeight, &outTransform); |
| 267 | reply->writeInt32(outWidth); |
| 268 | reply->writeInt32(outHeight); |
| 269 | reply->writeInt32(outTransform); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 270 | reply->writeInt32(result); |
| 271 | return NO_ERROR; |
| 272 | } break; |
| 273 | case CANCEL_BUFFER: { |
| 274 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 275 | int buf = data.readInt32(); |
| 276 | cancelBuffer(buf); |
| 277 | return NO_ERROR; |
| 278 | } break; |
| 279 | case SET_CROP: { |
| 280 | Rect reg; |
| 281 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 282 | reg.left = data.readFloat(); |
| 283 | reg.top = data.readFloat(); |
| 284 | reg.right = data.readFloat(); |
| 285 | reg.bottom = data.readFloat(); |
| 286 | status_t result = setCrop(reg); |
| 287 | reply->writeInt32(result); |
| 288 | return NO_ERROR; |
| 289 | } break; |
| 290 | case SET_TRANSFORM: { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 291 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 292 | uint32_t transform = data.readInt32(); |
| 293 | status_t result = setTransform(transform); |
| 294 | reply->writeInt32(result); |
| 295 | return NO_ERROR; |
| 296 | } break; |
Mathias Agopian | 7734ebf | 2011-07-13 15:24:42 -0700 | [diff] [blame] | 297 | case SET_SCALING_MODE: { |
| 298 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 299 | int mode = data.readInt32(); |
| 300 | status_t result = setScalingMode(mode); |
| 301 | reply->writeInt32(result); |
| 302 | return NO_ERROR; |
| 303 | } break; |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 304 | case QUERY: { |
| 305 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 306 | int value; |
| 307 | int what = data.readInt32(); |
| 308 | int res = query(what, &value); |
| 309 | reply->writeInt32(value); |
| 310 | reply->writeInt32(res); |
| 311 | return NO_ERROR; |
| 312 | } break; |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 313 | case SET_SYNCHRONOUS_MODE: { |
| 314 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 315 | bool enabled = data.readInt32(); |
| 316 | status_t res = setSynchronousMode(enabled); |
| 317 | reply->writeInt32(res); |
| 318 | return NO_ERROR; |
| 319 | } break; |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 320 | case CONNECT: { |
| 321 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 322 | int api = data.readInt32(); |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 323 | uint32_t outWidth, outHeight, outTransform; |
| 324 | status_t res = connect(api, |
| 325 | &outWidth, &outHeight, &outTransform); |
| 326 | reply->writeInt32(outWidth); |
| 327 | reply->writeInt32(outHeight); |
| 328 | reply->writeInt32(outTransform); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 329 | reply->writeInt32(res); |
| 330 | return NO_ERROR; |
| 331 | } break; |
| 332 | case DISCONNECT: { |
| 333 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 334 | int api = data.readInt32(); |
Mathias Agopian | 2773004 | 2011-07-14 20:20:58 -0700 | [diff] [blame] | 335 | status_t res = disconnect(api); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 336 | reply->writeInt32(res); |
| 337 | return NO_ERROR; |
| 338 | } break; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 339 | } |
| 340 | return BBinder::onTransact(code, data, reply, flags); |
| 341 | } |
| 342 | |
| 343 | // ---------------------------------------------------------------------------- |
| 344 | |
| 345 | }; // namespace android |