Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 1 | #include <log/log.h> |
| 2 | #include <private/dvr/IBufferHub.h> |
| 3 | |
| 4 | namespace android { |
| 5 | namespace dvr { |
| 6 | |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 7 | class BpBufferHub : public BpInterface<IBufferHub> { |
| 8 | public: |
| 9 | explicit BpBufferHub(const sp<IBinder>& impl) |
| 10 | : BpInterface<IBufferHub>(impl) {} |
| 11 | |
| 12 | sp<IBufferClient> createBuffer(uint32_t width, uint32_t height, |
| 13 | uint32_t layer_count, uint32_t format, |
| 14 | uint64_t usage, |
| 15 | uint64_t user_metadata_size) override; |
| 16 | }; |
| 17 | |
Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 18 | IMPLEMENT_META_INTERFACE(BufferHub, "android.dvr.IBufferHub"); |
| 19 | |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 20 | // Transaction code |
| 21 | enum { |
| 22 | CREATE_BUFFER = IBinder::FIRST_CALL_TRANSACTION, |
| 23 | }; |
| 24 | |
| 25 | sp<IBufferClient> BpBufferHub::createBuffer(uint32_t width, uint32_t height, |
| 26 | uint32_t layer_count, |
| 27 | uint32_t format, uint64_t usage, |
| 28 | uint64_t user_metadata_size) { |
| 29 | Parcel data, reply; |
| 30 | status_t ret = NO_ERROR; |
| 31 | ret |= data.writeInterfaceToken(IBufferHub::getInterfaceDescriptor()); |
| 32 | ret |= data.writeUint32(width); |
| 33 | ret |= data.writeUint32(height); |
| 34 | ret |= data.writeUint32(layer_count); |
| 35 | ret |= data.writeUint32(format); |
| 36 | ret |= data.writeUint64(usage); |
| 37 | ret |= data.writeUint64(user_metadata_size); |
| 38 | |
| 39 | if (ret != NO_ERROR) { |
| 40 | ALOGE("BpBufferHub::createBuffer: failed to write into parcel"); |
| 41 | return nullptr; |
| 42 | } |
| 43 | |
| 44 | ret = remote()->transact(CREATE_BUFFER, data, &reply); |
| 45 | if (ret == NO_ERROR) { |
| 46 | return interface_cast<IBufferClient>(reply.readStrongBinder()); |
| 47 | } else { |
| 48 | ALOGE("BpBufferHub::createBuffer: failed to transact; errno=%d", ret); |
| 49 | return nullptr; |
| 50 | } |
| 51 | } |
| 52 | |
Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 53 | status_t BnBufferHub::onTransact(uint32_t code, const Parcel& data, |
| 54 | Parcel* reply, uint32_t flags) { |
| 55 | switch (code) { |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 56 | case CREATE_BUFFER: { |
| 57 | CHECK_INTERFACE(IBufferHub, data, reply); |
| 58 | uint32_t width = data.readUint32(); |
| 59 | uint32_t height = data.readUint32(); |
| 60 | uint32_t layer_count = data.readUint32(); |
| 61 | uint32_t format = data.readUint32(); |
| 62 | uint64_t usage = data.readUint64(); |
| 63 | uint64_t user_metadata_size = data.readUint64(); |
| 64 | sp<IBufferClient> ret = createBuffer(width, height, layer_count, format, |
| 65 | usage, user_metadata_size); |
| 66 | return reply->writeStrongBinder(IInterface::asBinder(ret)); |
| 67 | } break; |
Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 68 | default: |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 69 | // Should not reach except binder defined transactions such as dumpsys |
Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 70 | return BBinder::onTransact(code, data, reply, flags); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | } // namespace dvr |
| 75 | } // namespace android |