| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [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 |  | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> | 
|  | 22 | #include <binder/IMemory.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 |  | 
|  | 24 | #include <ui/ISurface.h> | 
|  | 25 | #include <ui/Overlay.h> | 
|  | 26 |  | 
|  | 27 |  | 
|  | 28 | namespace android { | 
|  | 29 |  | 
|  | 30 | ISurface::BufferHeap::BufferHeap() | 
|  | 31 | : w(0), h(0), hor_stride(0), ver_stride(0), format(0), | 
|  | 32 | transform(0), flags(0) | 
|  | 33 | { | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | ISurface::BufferHeap::BufferHeap(uint32_t w, uint32_t h, | 
|  | 37 | int32_t hor_stride, int32_t ver_stride, | 
|  | 38 | PixelFormat format, const sp<IMemoryHeap>& heap) | 
|  | 39 | : w(w), h(h), hor_stride(hor_stride), ver_stride(ver_stride), | 
|  | 40 | format(format), transform(0), flags(0), heap(heap) | 
|  | 41 | { | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | ISurface::BufferHeap::BufferHeap(uint32_t w, uint32_t h, | 
|  | 45 | int32_t hor_stride, int32_t ver_stride, | 
|  | 46 | PixelFormat format, uint32_t transform, uint32_t flags, | 
|  | 47 | const sp<IMemoryHeap>& heap) | 
|  | 48 | : w(w), h(h), hor_stride(hor_stride), ver_stride(ver_stride), | 
|  | 49 | format(format), transform(transform), flags(flags), heap(heap) | 
|  | 50 | { | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 |  | 
|  | 54 | ISurface::BufferHeap::~BufferHeap() | 
|  | 55 | { | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | class BpSurface : public BpInterface<ISurface> | 
|  | 59 | { | 
|  | 60 | public: | 
|  | 61 | BpSurface(const sp<IBinder>& impl) | 
|  | 62 | : BpInterface<ISurface>(impl) | 
|  | 63 | { | 
|  | 64 | } | 
|  | 65 |  | 
|  | 66 | virtual status_t registerBuffers(const BufferHeap& buffers) | 
|  | 67 | { | 
|  | 68 | Parcel data, reply; | 
|  | 69 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); | 
|  | 70 | data.writeInt32(buffers.w); | 
|  | 71 | data.writeInt32(buffers.h); | 
|  | 72 | data.writeInt32(buffers.hor_stride); | 
|  | 73 | data.writeInt32(buffers.ver_stride); | 
|  | 74 | data.writeInt32(buffers.format); | 
|  | 75 | data.writeInt32(buffers.transform); | 
|  | 76 | data.writeInt32(buffers.flags); | 
|  | 77 | data.writeStrongBinder(buffers.heap->asBinder()); | 
|  | 78 | remote()->transact(REGISTER_BUFFERS, data, &reply); | 
|  | 79 | status_t result = reply.readInt32(); | 
|  | 80 | return result; | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | virtual void postBuffer(ssize_t offset) | 
|  | 84 | { | 
|  | 85 | Parcel data, reply; | 
|  | 86 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); | 
|  | 87 | data.writeInt32(offset); | 
|  | 88 | remote()->transact(POST_BUFFER, data, &reply, IBinder::FLAG_ONEWAY); | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | virtual void unregisterBuffers() | 
|  | 92 | { | 
|  | 93 | Parcel data, reply; | 
|  | 94 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); | 
|  | 95 | remote()->transact(UNREGISTER_BUFFERS, data, &reply); | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | virtual sp<OverlayRef> createOverlay( | 
|  | 99 | uint32_t w, uint32_t h, int32_t format) | 
|  | 100 | { | 
|  | 101 | Parcel data, reply; | 
|  | 102 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); | 
|  | 103 | data.writeInt32(w); | 
|  | 104 | data.writeInt32(h); | 
|  | 105 | data.writeInt32(format); | 
|  | 106 | remote()->transact(CREATE_OVERLAY, data, &reply); | 
|  | 107 | return OverlayRef::readFromParcel(reply); | 
|  | 108 | } | 
|  | 109 | }; | 
|  | 110 |  | 
|  | 111 | IMPLEMENT_META_INTERFACE(Surface, "android.ui.ISurface"); | 
|  | 112 |  | 
|  | 113 | // ---------------------------------------------------------------------- | 
|  | 114 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | status_t BnSurface::onTransact( | 
|  | 116 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 117 | { | 
|  | 118 | switch(code) { | 
|  | 119 | case REGISTER_BUFFERS: { | 
|  | 120 | CHECK_INTERFACE(ISurface, data, reply); | 
|  | 121 | BufferHeap buffer; | 
|  | 122 | buffer.w = data.readInt32(); | 
|  | 123 | buffer.h = data.readInt32(); | 
|  | 124 | buffer.hor_stride = data.readInt32(); | 
|  | 125 | buffer.ver_stride= data.readInt32(); | 
|  | 126 | buffer.format = data.readInt32(); | 
|  | 127 | buffer.transform = data.readInt32(); | 
|  | 128 | buffer.flags = data.readInt32(); | 
|  | 129 | buffer.heap = interface_cast<IMemoryHeap>(data.readStrongBinder()); | 
|  | 130 | status_t err = registerBuffers(buffer); | 
|  | 131 | reply->writeInt32(err); | 
|  | 132 | return NO_ERROR; | 
|  | 133 | } break; | 
|  | 134 | case UNREGISTER_BUFFERS: { | 
|  | 135 | CHECK_INTERFACE(ISurface, data, reply); | 
|  | 136 | unregisterBuffers(); | 
|  | 137 | return NO_ERROR; | 
|  | 138 | } break; | 
|  | 139 | case POST_BUFFER: { | 
|  | 140 | CHECK_INTERFACE(ISurface, data, reply); | 
|  | 141 | ssize_t offset = data.readInt32(); | 
|  | 142 | postBuffer(offset); | 
|  | 143 | return NO_ERROR; | 
|  | 144 | } break; | 
|  | 145 | case CREATE_OVERLAY: { | 
|  | 146 | CHECK_INTERFACE(ISurface, data, reply); | 
|  | 147 | int w = data.readInt32(); | 
|  | 148 | int h = data.readInt32(); | 
|  | 149 | int f = data.readInt32(); | 
|  | 150 | sp<OverlayRef> o = createOverlay(w, h, f); | 
|  | 151 | return OverlayRef::writeToParcel(reply, o); | 
|  | 152 | } break; | 
|  | 153 | default: | 
|  | 154 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 155 | } | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | }; // namespace android |