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, |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 39 | QUERY, |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 40 | SET_SYNCHRONOUS_MODE, |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 41 | CONNECT, |
| 42 | DISCONNECT, |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | |
| 46 | class BpSurfaceTexture : public BpInterface<ISurfaceTexture> |
| 47 | { |
| 48 | public: |
| 49 | BpSurfaceTexture(const sp<IBinder>& impl) |
| 50 | : BpInterface<ISurfaceTexture>(impl) |
| 51 | { |
| 52 | } |
| 53 | |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 54 | virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 55 | Parcel data, reply; |
| 56 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 57 | data.writeInt32(bufferIdx); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 58 | status_t result =remote()->transact(REQUEST_BUFFER, data, &reply); |
| 59 | if (result != NO_ERROR) { |
| 60 | return result; |
| 61 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 62 | bool nonNull = reply.readInt32(); |
| 63 | if (nonNull) { |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 64 | *buf = new GraphicBuffer(); |
| 65 | reply.read(**buf); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 66 | } |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 67 | result = reply.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 68 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | virtual status_t setBufferCount(int bufferCount) |
| 72 | { |
| 73 | Parcel data, reply; |
| 74 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 75 | data.writeInt32(bufferCount); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 76 | status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply); |
| 77 | if (result != NO_ERROR) { |
| 78 | return result; |
| 79 | } |
| 80 | result = reply.readInt32(); |
| 81 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 84 | virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h, |
| 85 | uint32_t format, uint32_t usage) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 86 | Parcel data, reply; |
| 87 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 88 | data.writeInt32(w); |
| 89 | data.writeInt32(h); |
| 90 | data.writeInt32(format); |
| 91 | data.writeInt32(usage); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 92 | status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); |
| 93 | if (result != NO_ERROR) { |
| 94 | return result; |
| 95 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 96 | *buf = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 97 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 98 | return result; |
| 99 | } |
| 100 | |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 101 | virtual status_t queueBuffer(int buf, int64_t timestamp, |
Mathias Agopian | 851ef8f | 2012-03-29 17:10:08 -0700 | [diff] [blame^] | 102 | const Rect& crop, int scalingMode, uint32_t transform, |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 103 | uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 104 | Parcel data, reply; |
| 105 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 106 | data.writeInt32(buf); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 107 | data.writeInt64(timestamp); |
Mathias Agopian | 851ef8f | 2012-03-29 17:10:08 -0700 | [diff] [blame^] | 108 | memcpy(data.writeInplace(sizeof(Rect)), &crop, sizeof(Rect)); |
| 109 | data.writeInt32(scalingMode); |
| 110 | data.writeInt32(transform); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 111 | status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); |
| 112 | if (result != NO_ERROR) { |
| 113 | return result; |
| 114 | } |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 115 | *outWidth = reply.readInt32(); |
| 116 | *outHeight = reply.readInt32(); |
| 117 | *outTransform = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 118 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 119 | return result; |
| 120 | } |
| 121 | |
| 122 | virtual void cancelBuffer(int buf) { |
| 123 | Parcel data, reply; |
| 124 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 125 | data.writeInt32(buf); |
| 126 | remote()->transact(CANCEL_BUFFER, data, &reply); |
| 127 | } |
| 128 | |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 129 | virtual int query(int what, int* value) { |
| 130 | Parcel data, reply; |
| 131 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 132 | data.writeInt32(what); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 133 | status_t result = remote()->transact(QUERY, data, &reply); |
| 134 | if (result != NO_ERROR) { |
| 135 | return result; |
| 136 | } |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 137 | value[0] = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 138 | result = reply.readInt32(); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 139 | return result; |
| 140 | } |
| 141 | |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 142 | virtual status_t setSynchronousMode(bool enabled) { |
| 143 | Parcel data, reply; |
| 144 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 145 | data.writeInt32(enabled); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 146 | status_t result = remote()->transact(SET_SYNCHRONOUS_MODE, data, &reply); |
| 147 | if (result != NO_ERROR) { |
| 148 | return result; |
| 149 | } |
| 150 | result = reply.readInt32(); |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 151 | return result; |
| 152 | } |
| 153 | |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 154 | virtual status_t connect(int api, |
| 155 | uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 156 | Parcel data, reply; |
| 157 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 158 | data.writeInt32(api); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 159 | status_t result = remote()->transact(CONNECT, data, &reply); |
| 160 | if (result != NO_ERROR) { |
| 161 | return result; |
| 162 | } |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 163 | *outWidth = reply.readInt32(); |
| 164 | *outHeight = reply.readInt32(); |
| 165 | *outTransform = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 166 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 167 | return result; |
| 168 | } |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 169 | |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 170 | virtual status_t disconnect(int api) { |
| 171 | Parcel data, reply; |
| 172 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 173 | data.writeInt32(api); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 174 | status_t result =remote()->transact(DISCONNECT, data, &reply); |
| 175 | if (result != NO_ERROR) { |
| 176 | return result; |
| 177 | } |
| 178 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 179 | return result; |
| 180 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | IMPLEMENT_META_INTERFACE(SurfaceTexture, "android.gui.SurfaceTexture"); |
| 184 | |
| 185 | // ---------------------------------------------------------------------- |
| 186 | |
| 187 | status_t BnSurfaceTexture::onTransact( |
| 188 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 189 | { |
| 190 | switch(code) { |
| 191 | case REQUEST_BUFFER: { |
| 192 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 193 | int bufferIdx = data.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 194 | sp<GraphicBuffer> buffer; |
| 195 | int result = requestBuffer(bufferIdx, &buffer); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 196 | reply->writeInt32(buffer != 0); |
| 197 | if (buffer != 0) { |
| 198 | reply->write(*buffer); |
| 199 | } |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 200 | reply->writeInt32(result); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 201 | return NO_ERROR; |
| 202 | } break; |
| 203 | case SET_BUFFER_COUNT: { |
| 204 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 205 | int bufferCount = data.readInt32(); |
| 206 | int result = setBufferCount(bufferCount); |
| 207 | reply->writeInt32(result); |
| 208 | return NO_ERROR; |
| 209 | } break; |
| 210 | case DEQUEUE_BUFFER: { |
| 211 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 212 | uint32_t w = data.readInt32(); |
| 213 | uint32_t h = data.readInt32(); |
| 214 | uint32_t format = data.readInt32(); |
| 215 | uint32_t usage = data.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 216 | int buf; |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 217 | int result = dequeueBuffer(&buf, w, h, format, usage); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 218 | reply->writeInt32(buf); |
| 219 | reply->writeInt32(result); |
| 220 | return NO_ERROR; |
| 221 | } break; |
| 222 | case QUEUE_BUFFER: { |
| 223 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 224 | int buf = data.readInt32(); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 225 | int64_t timestamp = data.readInt64(); |
Mathias Agopian | 851ef8f | 2012-03-29 17:10:08 -0700 | [diff] [blame^] | 226 | Rect crop( *reinterpret_cast<Rect const *>(data.readInplace(sizeof(Rect))) ); |
| 227 | int scalingMode = data.readInt32(); |
| 228 | uint32_t transform = data.readInt32(); |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 229 | uint32_t outWidth, outHeight, outTransform; |
| 230 | status_t result = queueBuffer(buf, timestamp, |
Mathias Agopian | 851ef8f | 2012-03-29 17:10:08 -0700 | [diff] [blame^] | 231 | crop, scalingMode, transform, |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 232 | &outWidth, &outHeight, &outTransform); |
| 233 | reply->writeInt32(outWidth); |
| 234 | reply->writeInt32(outHeight); |
| 235 | reply->writeInt32(outTransform); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 236 | reply->writeInt32(result); |
| 237 | return NO_ERROR; |
| 238 | } break; |
| 239 | case CANCEL_BUFFER: { |
| 240 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 241 | int buf = data.readInt32(); |
| 242 | cancelBuffer(buf); |
| 243 | return NO_ERROR; |
| 244 | } break; |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 245 | case QUERY: { |
| 246 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 247 | int value; |
| 248 | int what = data.readInt32(); |
| 249 | int res = query(what, &value); |
| 250 | reply->writeInt32(value); |
| 251 | reply->writeInt32(res); |
| 252 | return NO_ERROR; |
| 253 | } break; |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 254 | case SET_SYNCHRONOUS_MODE: { |
| 255 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 256 | bool enabled = data.readInt32(); |
| 257 | status_t res = setSynchronousMode(enabled); |
| 258 | reply->writeInt32(res); |
| 259 | return NO_ERROR; |
| 260 | } break; |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 261 | case CONNECT: { |
| 262 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 263 | int api = data.readInt32(); |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 264 | uint32_t outWidth, outHeight, outTransform; |
| 265 | status_t res = connect(api, |
| 266 | &outWidth, &outHeight, &outTransform); |
| 267 | reply->writeInt32(outWidth); |
| 268 | reply->writeInt32(outHeight); |
| 269 | reply->writeInt32(outTransform); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 270 | reply->writeInt32(res); |
| 271 | return NO_ERROR; |
| 272 | } break; |
| 273 | case DISCONNECT: { |
| 274 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 275 | int api = data.readInt32(); |
Mathias Agopian | 2773004 | 2011-07-14 20:20:58 -0700 | [diff] [blame] | 276 | status_t res = disconnect(api); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 277 | reply->writeInt32(res); |
| 278 | return NO_ERROR; |
| 279 | } break; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 280 | } |
| 281 | return BBinder::onTransact(code, data, reply, flags); |
| 282 | } |
| 283 | |
| 284 | // ---------------------------------------------------------------------------- |
| 285 | |
| 286 | }; // namespace android |