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 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 28 | #include <gui/IGraphicBufferProducer.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 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 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 46 | class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 47 | { |
| 48 | public: |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 49 | BpGraphicBufferProducer(const sp<IBinder>& impl) |
| 50 | : BpInterface<IGraphicBufferProducer>(impl) |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 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; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 56 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 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(); |
Lingyun Zhu | 2aff702 | 2012-11-20 19:24:35 +0800 | [diff] [blame^] | 65 | result = reply.read(**buf); |
| 66 | if(result != NO_ERROR) { |
| 67 | (*buf).clear(); |
| 68 | return result; |
| 69 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 70 | } |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 71 | result = reply.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 72 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | virtual status_t setBufferCount(int bufferCount) |
| 76 | { |
| 77 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 78 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 79 | data.writeInt32(bufferCount); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 80 | status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply); |
| 81 | if (result != NO_ERROR) { |
| 82 | return result; |
| 83 | } |
| 84 | result = reply.readInt32(); |
| 85 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Jesse Hall | 4c00cc1 | 2013-03-15 21:34:30 -0700 | [diff] [blame] | 88 | virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 89 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 90 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 91 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 92 | data.writeInt32(w); |
| 93 | data.writeInt32(h); |
| 94 | data.writeInt32(format); |
| 95 | data.writeInt32(usage); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 96 | status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); |
| 97 | if (result != NO_ERROR) { |
| 98 | return result; |
| 99 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 100 | *buf = reply.readInt32(); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 101 | bool fenceWasWritten = reply.readInt32(); |
| 102 | if (fenceWasWritten) { |
| 103 | // If the fence was written by the callee, then overwrite the |
| 104 | // caller's fence here. If it wasn't written then don't touch the |
| 105 | // caller's fence. |
Jesse Hall | 4c00cc1 | 2013-03-15 21:34:30 -0700 | [diff] [blame] | 106 | *fence = new Fence(); |
| 107 | reply.read(*(fence->get())); |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 108 | } |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 109 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 110 | return result; |
| 111 | } |
| 112 | |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 113 | virtual status_t queueBuffer(int buf, |
| 114 | const QueueBufferInput& input, QueueBufferOutput* output) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 115 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 116 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 117 | data.writeInt32(buf); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 118 | data.write(input); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 119 | status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); |
| 120 | if (result != NO_ERROR) { |
| 121 | return result; |
| 122 | } |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 123 | memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 124 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 125 | return result; |
| 126 | } |
| 127 | |
Jesse Hall | 4c00cc1 | 2013-03-15 21:34:30 -0700 | [diff] [blame] | 128 | virtual void cancelBuffer(int buf, const sp<Fence>& fence) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 129 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 130 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 131 | data.writeInt32(buf); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 132 | data.write(*fence.get()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 133 | remote()->transact(CANCEL_BUFFER, data, &reply); |
| 134 | } |
| 135 | |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 136 | virtual int query(int what, int* value) { |
| 137 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 138 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 139 | data.writeInt32(what); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 140 | status_t result = remote()->transact(QUERY, data, &reply); |
| 141 | if (result != NO_ERROR) { |
| 142 | return result; |
| 143 | } |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 144 | value[0] = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 145 | result = reply.readInt32(); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 146 | return result; |
| 147 | } |
| 148 | |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 149 | virtual status_t setSynchronousMode(bool enabled) { |
| 150 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 151 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 152 | data.writeInt32(enabled); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 153 | status_t result = remote()->transact(SET_SYNCHRONOUS_MODE, data, &reply); |
| 154 | if (result != NO_ERROR) { |
| 155 | return result; |
| 156 | } |
| 157 | result = reply.readInt32(); |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 158 | return result; |
| 159 | } |
| 160 | |
Mathias Agopian | 24202f5 | 2012-04-23 14:28:58 -0700 | [diff] [blame] | 161 | virtual status_t connect(int api, QueueBufferOutput* output) { |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 162 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 163 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 164 | data.writeInt32(api); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 165 | status_t result = remote()->transact(CONNECT, data, &reply); |
| 166 | if (result != NO_ERROR) { |
| 167 | return result; |
| 168 | } |
Mathias Agopian | 24202f5 | 2012-04-23 14:28:58 -0700 | [diff] [blame] | 169 | memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 170 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 171 | return result; |
| 172 | } |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 173 | |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 174 | virtual status_t disconnect(int api) { |
| 175 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 176 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 177 | data.writeInt32(api); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 178 | status_t result =remote()->transact(DISCONNECT, data, &reply); |
| 179 | if (result != NO_ERROR) { |
| 180 | return result; |
| 181 | } |
| 182 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 183 | return result; |
| 184 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 185 | }; |
| 186 | |
Andy McFadden | 466a192 | 2013-01-08 11:25:51 -0800 | [diff] [blame] | 187 | IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 188 | |
| 189 | // ---------------------------------------------------------------------- |
| 190 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 191 | status_t BnGraphicBufferProducer::onTransact( |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 192 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 193 | { |
| 194 | switch(code) { |
| 195 | case REQUEST_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 196 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 197 | int bufferIdx = data.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 198 | sp<GraphicBuffer> buffer; |
| 199 | int result = requestBuffer(bufferIdx, &buffer); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 200 | reply->writeInt32(buffer != 0); |
| 201 | if (buffer != 0) { |
| 202 | reply->write(*buffer); |
| 203 | } |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 204 | reply->writeInt32(result); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 205 | return NO_ERROR; |
| 206 | } break; |
| 207 | case SET_BUFFER_COUNT: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 208 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 209 | int bufferCount = data.readInt32(); |
| 210 | int result = setBufferCount(bufferCount); |
| 211 | reply->writeInt32(result); |
| 212 | return NO_ERROR; |
| 213 | } break; |
| 214 | case DEQUEUE_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 215 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 216 | uint32_t w = data.readInt32(); |
| 217 | uint32_t h = data.readInt32(); |
| 218 | uint32_t format = data.readInt32(); |
| 219 | uint32_t usage = data.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 220 | int buf; |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 221 | sp<Fence> fence; |
Jesse Hall | 4c00cc1 | 2013-03-15 21:34:30 -0700 | [diff] [blame] | 222 | int result = dequeueBuffer(&buf, &fence, w, h, format, usage); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 223 | reply->writeInt32(buf); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 224 | reply->writeInt32(fence != NULL); |
| 225 | if (fence != NULL) { |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 226 | reply->write(*fence.get()); |
| 227 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 228 | reply->writeInt32(result); |
| 229 | return NO_ERROR; |
| 230 | } break; |
| 231 | case QUEUE_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 232 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 233 | int buf = data.readInt32(); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 234 | QueueBufferInput input(data); |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 235 | QueueBufferOutput* const output = |
| 236 | reinterpret_cast<QueueBufferOutput *>( |
| 237 | reply->writeInplace(sizeof(QueueBufferOutput))); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 238 | status_t result = queueBuffer(buf, input, output); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 239 | reply->writeInt32(result); |
| 240 | return NO_ERROR; |
| 241 | } break; |
| 242 | case CANCEL_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 243 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 244 | int buf = data.readInt32(); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 245 | sp<Fence> fence = new Fence(); |
| 246 | data.read(*fence.get()); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 247 | cancelBuffer(buf, fence); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 248 | return NO_ERROR; |
| 249 | } break; |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 250 | case QUERY: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 251 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 252 | int value; |
| 253 | int what = data.readInt32(); |
| 254 | int res = query(what, &value); |
| 255 | reply->writeInt32(value); |
| 256 | reply->writeInt32(res); |
| 257 | return NO_ERROR; |
| 258 | } break; |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 259 | case SET_SYNCHRONOUS_MODE: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 260 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 261 | bool enabled = data.readInt32(); |
| 262 | status_t res = setSynchronousMode(enabled); |
| 263 | reply->writeInt32(res); |
| 264 | return NO_ERROR; |
| 265 | } break; |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 266 | case CONNECT: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 267 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 268 | int api = data.readInt32(); |
Mathias Agopian | 24202f5 | 2012-04-23 14:28:58 -0700 | [diff] [blame] | 269 | QueueBufferOutput* const output = |
| 270 | reinterpret_cast<QueueBufferOutput *>( |
| 271 | reply->writeInplace(sizeof(QueueBufferOutput))); |
| 272 | status_t res = connect(api, output); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 273 | reply->writeInt32(res); |
| 274 | return NO_ERROR; |
| 275 | } break; |
| 276 | case DISCONNECT: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 277 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 278 | int api = data.readInt32(); |
Mathias Agopian | 2773004 | 2011-07-14 20:20:58 -0700 | [diff] [blame] | 279 | status_t res = disconnect(api); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 280 | reply->writeInt32(res); |
| 281 | return NO_ERROR; |
| 282 | } break; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 283 | } |
| 284 | return BBinder::onTransact(code, data, reply, flags); |
| 285 | } |
| 286 | |
| 287 | // ---------------------------------------------------------------------------- |
| 288 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 289 | IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) { |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 290 | parcel.read(*this); |
| 291 | } |
| 292 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 293 | size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 294 | { |
| 295 | return sizeof(timestamp) |
| 296 | + sizeof(crop) |
| 297 | + sizeof(scalingMode) |
| 298 | + sizeof(transform) |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 299 | + fence->getFlattenedSize(); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 302 | size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 303 | { |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 304 | return fence->getFdCount(); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 307 | status_t IGraphicBufferProducer::QueueBufferInput::flatten(void* buffer, size_t size, |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 308 | int fds[], size_t count) const |
| 309 | { |
| 310 | status_t err = NO_ERROR; |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 311 | char* p = (char*)buffer; |
| 312 | memcpy(p, ×tamp, sizeof(timestamp)); p += sizeof(timestamp); |
| 313 | memcpy(p, &crop, sizeof(crop)); p += sizeof(crop); |
| 314 | memcpy(p, &scalingMode, sizeof(scalingMode)); p += sizeof(scalingMode); |
| 315 | memcpy(p, &transform, sizeof(transform)); p += sizeof(transform); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 316 | err = fence->flatten(p, size - (p - (char*)buffer), fds, count); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 317 | return err; |
| 318 | } |
| 319 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 320 | status_t IGraphicBufferProducer::QueueBufferInput::unflatten(void const* buffer, |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 321 | size_t size, int fds[], size_t count) |
| 322 | { |
| 323 | status_t err = NO_ERROR; |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 324 | const char* p = (const char*)buffer; |
| 325 | memcpy(×tamp, p, sizeof(timestamp)); p += sizeof(timestamp); |
| 326 | memcpy(&crop, p, sizeof(crop)); p += sizeof(crop); |
| 327 | memcpy(&scalingMode, p, sizeof(scalingMode)); p += sizeof(scalingMode); |
| 328 | memcpy(&transform, p, sizeof(transform)); p += sizeof(transform); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 329 | fence = new Fence(); |
| 330 | err = fence->unflatten(p, size - (p - (const char*)buffer), fds, count); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 331 | return err; |
| 332 | } |
| 333 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 334 | }; // namespace android |