The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2007 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 <stdio.h> |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | |
| 21 | #include <utils/Parcel.h> |
| 22 | #include <utils/IMemory.h> |
| 23 | |
| 24 | #include <ui/ISurface.h> |
| 25 | |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | enum { |
| 30 | REGISTER_BUFFERS = IBinder::FIRST_CALL_TRANSACTION, |
| 31 | UNREGISTER_BUFFERS, |
| 32 | POST_BUFFER, // one-way transaction |
| 33 | }; |
| 34 | |
| 35 | class BpSurface : public BpInterface<ISurface> |
| 36 | { |
| 37 | public: |
| 38 | BpSurface(const sp<IBinder>& impl) |
| 39 | : BpInterface<ISurface>(impl) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | virtual status_t registerBuffers(int w, int h, int hstride, int vstride, |
| 44 | PixelFormat format, const sp<IMemoryHeap>& heap) |
| 45 | { |
| 46 | Parcel data, reply; |
| 47 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 48 | data.writeInt32(w); |
| 49 | data.writeInt32(h); |
| 50 | data.writeInt32(hstride); |
| 51 | data.writeInt32(vstride); |
| 52 | data.writeInt32(format); |
| 53 | data.writeStrongBinder(heap->asBinder()); |
| 54 | remote()->transact(REGISTER_BUFFERS, data, &reply); |
| 55 | status_t result = reply.readInt32(); |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | virtual void postBuffer(ssize_t offset) |
| 60 | { |
| 61 | Parcel data, reply; |
| 62 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 63 | data.writeInt32(offset); |
| 64 | remote()->transact(POST_BUFFER, data, &reply, IBinder::FLAG_ONEWAY); |
| 65 | } |
| 66 | |
| 67 | virtual void unregisterBuffers() |
| 68 | { |
| 69 | Parcel data, reply; |
| 70 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 71 | remote()->transact(UNREGISTER_BUFFERS, data, &reply); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | IMPLEMENT_META_INTERFACE(Surface, "android.ui.ISurface"); |
| 76 | |
| 77 | // ---------------------------------------------------------------------- |
| 78 | |
| 79 | #define CHECK_INTERFACE(interface, data, reply) \ |
| 80 | do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \ |
| 81 | LOGW("Call incorrectly routed to " #interface); \ |
| 82 | return PERMISSION_DENIED; \ |
| 83 | } } while (0) |
| 84 | |
| 85 | status_t BnSurface::onTransact( |
| 86 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 87 | { |
| 88 | switch(code) { |
| 89 | case REGISTER_BUFFERS: { |
| 90 | CHECK_INTERFACE(ISurface, data, reply); |
| 91 | int w = data.readInt32(); |
| 92 | int h = data.readInt32(); |
| 93 | int hs= data.readInt32(); |
| 94 | int vs= data.readInt32(); |
| 95 | PixelFormat f = data.readInt32(); |
| 96 | sp<IMemoryHeap> heap(interface_cast<IMemoryHeap>(data.readStrongBinder())); |
| 97 | status_t err = registerBuffers(w,h,hs,vs,f,heap); |
| 98 | reply->writeInt32(err); |
| 99 | return NO_ERROR; |
| 100 | } break; |
| 101 | case UNREGISTER_BUFFERS: { |
| 102 | CHECK_INTERFACE(ISurface, data, reply); |
| 103 | unregisterBuffers(); |
| 104 | return NO_ERROR; |
| 105 | } break; |
| 106 | case POST_BUFFER: { |
| 107 | CHECK_INTERFACE(ISurface, data, reply); |
| 108 | ssize_t offset = data.readInt32(); |
| 109 | postBuffer(offset); |
| 110 | return NO_ERROR; |
| 111 | } break; |
| 112 | default: |
| 113 | return BBinder::onTransact(code, data, reply, flags); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | }; // namespace android |