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; |
Fan Xu | 3a96ccd | 2018-10-23 13:05:11 -0700 | [diff] [blame] | 16 | |
| 17 | status_t importBuffer(uint64_t token, sp<IBufferClient>* outClient) override; |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 18 | }; |
| 19 | |
Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 20 | IMPLEMENT_META_INTERFACE(BufferHub, "android.dvr.IBufferHub"); |
| 21 | |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 22 | // Transaction code |
| 23 | enum { |
| 24 | CREATE_BUFFER = IBinder::FIRST_CALL_TRANSACTION, |
Fan Xu | 3a96ccd | 2018-10-23 13:05:11 -0700 | [diff] [blame] | 25 | IMPORT_BUFFER, |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | sp<IBufferClient> BpBufferHub::createBuffer(uint32_t width, uint32_t height, |
| 29 | uint32_t layer_count, |
| 30 | uint32_t format, uint64_t usage, |
| 31 | uint64_t user_metadata_size) { |
| 32 | Parcel data, reply; |
| 33 | status_t ret = NO_ERROR; |
| 34 | ret |= data.writeInterfaceToken(IBufferHub::getInterfaceDescriptor()); |
| 35 | ret |= data.writeUint32(width); |
| 36 | ret |= data.writeUint32(height); |
| 37 | ret |= data.writeUint32(layer_count); |
| 38 | ret |= data.writeUint32(format); |
| 39 | ret |= data.writeUint64(usage); |
| 40 | ret |= data.writeUint64(user_metadata_size); |
| 41 | |
| 42 | if (ret != NO_ERROR) { |
| 43 | ALOGE("BpBufferHub::createBuffer: failed to write into parcel"); |
| 44 | return nullptr; |
| 45 | } |
| 46 | |
| 47 | ret = remote()->transact(CREATE_BUFFER, data, &reply); |
| 48 | if (ret == NO_ERROR) { |
| 49 | return interface_cast<IBufferClient>(reply.readStrongBinder()); |
| 50 | } else { |
| 51 | ALOGE("BpBufferHub::createBuffer: failed to transact; errno=%d", ret); |
| 52 | return nullptr; |
| 53 | } |
| 54 | } |
| 55 | |
Fan Xu | 3a96ccd | 2018-10-23 13:05:11 -0700 | [diff] [blame] | 56 | status_t BpBufferHub::importBuffer(uint64_t token, |
| 57 | sp<IBufferClient>* outClient) { |
| 58 | Parcel data, reply; |
| 59 | status_t ret = NO_ERROR; |
| 60 | ret |= data.writeInterfaceToken(IBufferHub::getInterfaceDescriptor()); |
| 61 | ret |= data.writeUint64(token); |
| 62 | if (ret != NO_ERROR) { |
| 63 | ALOGE("BpBufferHub::importBuffer: failed to write into parcel"); |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | ret = remote()->transact(IMPORT_BUFFER, data, &reply); |
| 68 | if (ret == NO_ERROR) { |
| 69 | *outClient = interface_cast<IBufferClient>(reply.readStrongBinder()); |
| 70 | return NO_ERROR; |
| 71 | } else { |
| 72 | ALOGE("BpBufferHub::importBuffer: failed to transact; errno=%d", ret); |
| 73 | return ret; |
| 74 | } |
| 75 | } |
| 76 | |
Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 77 | status_t BnBufferHub::onTransact(uint32_t code, const Parcel& data, |
| 78 | Parcel* reply, uint32_t flags) { |
| 79 | switch (code) { |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 80 | case CREATE_BUFFER: { |
| 81 | CHECK_INTERFACE(IBufferHub, data, reply); |
| 82 | uint32_t width = data.readUint32(); |
| 83 | uint32_t height = data.readUint32(); |
| 84 | uint32_t layer_count = data.readUint32(); |
| 85 | uint32_t format = data.readUint32(); |
| 86 | uint64_t usage = data.readUint64(); |
| 87 | uint64_t user_metadata_size = data.readUint64(); |
| 88 | sp<IBufferClient> ret = createBuffer(width, height, layer_count, format, |
| 89 | usage, user_metadata_size); |
| 90 | return reply->writeStrongBinder(IInterface::asBinder(ret)); |
Fan Xu | d94e2ee | 2018-10-19 14:42:45 -0700 | [diff] [blame] | 91 | } |
Fan Xu | 3a96ccd | 2018-10-23 13:05:11 -0700 | [diff] [blame] | 92 | case IMPORT_BUFFER: { |
| 93 | CHECK_INTERFACE(IBufferHub, data, reply); |
| 94 | uint64_t token = data.readUint64(); |
| 95 | sp<IBufferClient> client; |
| 96 | status_t ret = importBuffer(token, &client); |
| 97 | if (ret == NO_ERROR) { |
| 98 | return reply->writeStrongBinder(IInterface::asBinder(client)); |
| 99 | } else { |
| 100 | return ret; |
| 101 | } |
| 102 | } |
Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 103 | default: |
Fan Xu | 6df8c2a | 2018-10-10 15:53:21 -0700 | [diff] [blame] | 104 | // Should not reach except binder defined transactions such as dumpsys |
Fan Xu | f35719a | 2018-10-10 11:38:31 -0700 | [diff] [blame] | 105 | return BBinder::onTransact(code, data, reply, flags); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | } // namespace dvr |
| 110 | } // namespace android |