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