Jamie Gennis | 68e4a7a | 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, |
Jamie Gennis | 83bac21 | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 41 | GET_ALLOCATOR, |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | |
| 45 | class BpSurfaceTexture : public BpInterface<ISurfaceTexture> |
| 46 | { |
| 47 | public: |
| 48 | BpSurfaceTexture(const sp<IBinder>& impl) |
| 49 | : BpInterface<ISurfaceTexture>(impl) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | virtual sp<GraphicBuffer> requestBuffer(int bufferIdx, |
| 54 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) { |
| 55 | Parcel data, reply; |
| 56 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 57 | data.writeInt32(bufferIdx); |
| 58 | data.writeInt32(w); |
| 59 | data.writeInt32(h); |
| 60 | data.writeInt32(format); |
| 61 | data.writeInt32(usage); |
| 62 | remote()->transact(REQUEST_BUFFER, data, &reply); |
| 63 | sp<GraphicBuffer> buffer; |
| 64 | bool nonNull = reply.readInt32(); |
| 65 | if (nonNull) { |
| 66 | buffer = new GraphicBuffer(); |
| 67 | reply.read(*buffer); |
| 68 | } |
| 69 | return buffer; |
| 70 | } |
| 71 | |
| 72 | virtual status_t setBufferCount(int bufferCount) |
| 73 | { |
| 74 | Parcel data, reply; |
| 75 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 76 | data.writeInt32(bufferCount); |
| 77 | remote()->transact(SET_BUFFER_COUNT, data, &reply); |
| 78 | status_t err = reply.readInt32(); |
| 79 | return err; |
| 80 | } |
| 81 | |
| 82 | virtual status_t dequeueBuffer(int *buf) { |
| 83 | Parcel data, reply; |
| 84 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 85 | remote()->transact(DEQUEUE_BUFFER, data, &reply); |
| 86 | *buf = reply.readInt32(); |
| 87 | int result = reply.readInt32(); |
| 88 | return result; |
| 89 | } |
| 90 | |
| 91 | virtual status_t queueBuffer(int buf) { |
| 92 | Parcel data, reply; |
| 93 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 94 | data.writeInt32(buf); |
| 95 | remote()->transact(QUEUE_BUFFER, data, &reply); |
| 96 | status_t result = reply.readInt32(); |
| 97 | return result; |
| 98 | } |
| 99 | |
| 100 | virtual void cancelBuffer(int buf) { |
| 101 | Parcel data, reply; |
| 102 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 103 | data.writeInt32(buf); |
| 104 | remote()->transact(CANCEL_BUFFER, data, &reply); |
| 105 | } |
| 106 | |
| 107 | virtual status_t setCrop(const Rect& reg) { |
| 108 | Parcel data, reply; |
| 109 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 110 | data.writeFloat(reg.left); |
| 111 | data.writeFloat(reg.top); |
| 112 | data.writeFloat(reg.right); |
| 113 | data.writeFloat(reg.bottom); |
| 114 | remote()->transact(SET_CROP, data, &reply); |
| 115 | status_t result = reply.readInt32(); |
| 116 | return result; |
| 117 | } |
| 118 | |
| 119 | virtual status_t setTransform(uint32_t transform) { |
| 120 | Parcel data, reply; |
| 121 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 122 | data.writeInt32(transform); |
| 123 | remote()->transact(SET_TRANSFORM, data, &reply); |
| 124 | status_t result = reply.readInt32(); |
| 125 | return result; |
| 126 | } |
Jamie Gennis | 83bac21 | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 127 | |
| 128 | virtual sp<IBinder> getAllocator() { |
| 129 | Parcel data, reply; |
| 130 | data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor()); |
| 131 | remote()->transact(GET_ALLOCATOR, data, &reply); |
| 132 | return reply.readStrongBinder(); |
| 133 | } |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | IMPLEMENT_META_INTERFACE(SurfaceTexture, "android.gui.SurfaceTexture"); |
| 137 | |
| 138 | // ---------------------------------------------------------------------- |
| 139 | |
| 140 | status_t BnSurfaceTexture::onTransact( |
| 141 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 142 | { |
| 143 | switch(code) { |
| 144 | case REQUEST_BUFFER: { |
| 145 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 146 | int bufferIdx = data.readInt32(); |
| 147 | uint32_t w = data.readInt32(); |
| 148 | uint32_t h = data.readInt32(); |
| 149 | uint32_t format = data.readInt32(); |
| 150 | uint32_t usage = data.readInt32(); |
| 151 | sp<GraphicBuffer> buffer(requestBuffer(bufferIdx, w, h, format, |
| 152 | usage)); |
| 153 | reply->writeInt32(buffer != 0); |
| 154 | if (buffer != 0) { |
| 155 | reply->write(*buffer); |
| 156 | } |
| 157 | return NO_ERROR; |
| 158 | } break; |
| 159 | case SET_BUFFER_COUNT: { |
| 160 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 161 | int bufferCount = data.readInt32(); |
| 162 | int result = setBufferCount(bufferCount); |
| 163 | reply->writeInt32(result); |
| 164 | return NO_ERROR; |
| 165 | } break; |
| 166 | case DEQUEUE_BUFFER: { |
| 167 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 168 | int buf; |
| 169 | int result = dequeueBuffer(&buf); |
| 170 | reply->writeInt32(buf); |
| 171 | reply->writeInt32(result); |
| 172 | return NO_ERROR; |
| 173 | } break; |
| 174 | case QUEUE_BUFFER: { |
| 175 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 176 | int buf = data.readInt32(); |
| 177 | status_t result = queueBuffer(buf); |
| 178 | reply->writeInt32(result); |
| 179 | return NO_ERROR; |
| 180 | } break; |
| 181 | case CANCEL_BUFFER: { |
| 182 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 183 | int buf = data.readInt32(); |
| 184 | cancelBuffer(buf); |
| 185 | return NO_ERROR; |
| 186 | } break; |
| 187 | case SET_CROP: { |
| 188 | Rect reg; |
| 189 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 190 | reg.left = data.readFloat(); |
| 191 | reg.top = data.readFloat(); |
| 192 | reg.right = data.readFloat(); |
| 193 | reg.bottom = data.readFloat(); |
| 194 | status_t result = setCrop(reg); |
| 195 | reply->writeInt32(result); |
| 196 | return NO_ERROR; |
| 197 | } break; |
| 198 | case SET_TRANSFORM: { |
| 199 | Rect reg; |
| 200 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 201 | uint32_t transform = data.readInt32(); |
| 202 | status_t result = setTransform(transform); |
| 203 | reply->writeInt32(result); |
| 204 | return NO_ERROR; |
| 205 | } break; |
Jamie Gennis | 83bac21 | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 206 | case GET_ALLOCATOR: { |
| 207 | CHECK_INTERFACE(ISurfaceTexture, data, reply); |
| 208 | sp<IBinder> result = getAllocator(); |
| 209 | reply->writeStrongBinder(result); |
| 210 | return NO_ERROR; |
| 211 | } break; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 212 | } |
| 213 | return BBinder::onTransact(code, data, reply, flags); |
| 214 | } |
| 215 | |
| 216 | // ---------------------------------------------------------------------------- |
| 217 | |
| 218 | }; // namespace android |