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 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 17 | #define LOG_TAG "ISurface" |
| 18 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/Parcel.h> |
| 24 | #include <utils/IMemory.h> |
| 25 | |
| 26 | #include <ui/ISurface.h> |
| 27 | #include <ui/Overlay.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <ui/Surface.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Mathias Agopian | 7189c00 | 2009-05-05 18:11:11 -0700 | [diff] [blame^] | 30 | #include <private/ui/SurfaceBuffer.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 34 | // ---------------------------------------------------------------------- |
| 35 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | ISurface::BufferHeap::BufferHeap() |
| 37 | : w(0), h(0), hor_stride(0), ver_stride(0), format(0), |
| 38 | transform(0), flags(0) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | ISurface::BufferHeap::BufferHeap(uint32_t w, uint32_t h, |
| 43 | int32_t hor_stride, int32_t ver_stride, |
| 44 | PixelFormat format, const sp<IMemoryHeap>& heap) |
| 45 | : w(w), h(h), hor_stride(hor_stride), ver_stride(ver_stride), |
| 46 | format(format), transform(0), flags(0), heap(heap) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | ISurface::BufferHeap::BufferHeap(uint32_t w, uint32_t h, |
| 51 | int32_t hor_stride, int32_t ver_stride, |
| 52 | PixelFormat format, uint32_t transform, uint32_t flags, |
| 53 | const sp<IMemoryHeap>& heap) |
| 54 | : w(w), h(h), hor_stride(hor_stride), ver_stride(ver_stride), |
| 55 | format(format), transform(transform), flags(flags), heap(heap) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | |
| 60 | ISurface::BufferHeap::~BufferHeap() |
| 61 | { |
| 62 | } |
| 63 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 64 | // ---------------------------------------------------------------------- |
| 65 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | class BpSurface : public BpInterface<ISurface> |
| 67 | { |
| 68 | public: |
| 69 | BpSurface(const sp<IBinder>& impl) |
| 70 | : BpInterface<ISurface>(impl) |
| 71 | { |
| 72 | } |
| 73 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 74 | virtual sp<SurfaceBuffer> getBuffer() |
| 75 | { |
| 76 | Parcel data, reply; |
| 77 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 78 | remote()->transact(GET_BUFFER, data, &reply); |
| 79 | sp<SurfaceBuffer> buffer = new SurfaceBuffer(reply); |
| 80 | return buffer; |
| 81 | } |
| 82 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | virtual status_t registerBuffers(const BufferHeap& buffers) |
| 84 | { |
| 85 | Parcel data, reply; |
| 86 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 87 | data.writeInt32(buffers.w); |
| 88 | data.writeInt32(buffers.h); |
| 89 | data.writeInt32(buffers.hor_stride); |
| 90 | data.writeInt32(buffers.ver_stride); |
| 91 | data.writeInt32(buffers.format); |
| 92 | data.writeInt32(buffers.transform); |
| 93 | data.writeInt32(buffers.flags); |
| 94 | data.writeStrongBinder(buffers.heap->asBinder()); |
| 95 | remote()->transact(REGISTER_BUFFERS, data, &reply); |
| 96 | status_t result = reply.readInt32(); |
| 97 | return result; |
| 98 | } |
| 99 | |
| 100 | virtual void postBuffer(ssize_t offset) |
| 101 | { |
| 102 | Parcel data, reply; |
| 103 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 104 | data.writeInt32(offset); |
| 105 | remote()->transact(POST_BUFFER, data, &reply, IBinder::FLAG_ONEWAY); |
| 106 | } |
| 107 | |
| 108 | virtual void unregisterBuffers() |
| 109 | { |
| 110 | Parcel data, reply; |
| 111 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 112 | remote()->transact(UNREGISTER_BUFFERS, data, &reply); |
| 113 | } |
| 114 | |
| 115 | virtual sp<OverlayRef> createOverlay( |
| 116 | uint32_t w, uint32_t h, int32_t format) |
| 117 | { |
| 118 | Parcel data, reply; |
| 119 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 120 | data.writeInt32(w); |
| 121 | data.writeInt32(h); |
| 122 | data.writeInt32(format); |
| 123 | remote()->transact(CREATE_OVERLAY, data, &reply); |
| 124 | return OverlayRef::readFromParcel(reply); |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | IMPLEMENT_META_INTERFACE(Surface, "android.ui.ISurface"); |
| 129 | |
| 130 | // ---------------------------------------------------------------------- |
| 131 | |
| 132 | #define CHECK_INTERFACE(interface, data, reply) \ |
| 133 | do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \ |
| 134 | LOGW("Call incorrectly routed to " #interface); \ |
| 135 | return PERMISSION_DENIED; \ |
| 136 | } } while (0) |
| 137 | |
| 138 | status_t BnSurface::onTransact( |
| 139 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 140 | { |
| 141 | switch(code) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 142 | case GET_BUFFER: { |
| 143 | CHECK_INTERFACE(ISurface, data, reply); |
| 144 | sp<SurfaceBuffer> buffer(getBuffer()); |
| 145 | return SurfaceBuffer::writeToParcel(reply, buffer.get()); |
| 146 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | case REGISTER_BUFFERS: { |
| 148 | CHECK_INTERFACE(ISurface, data, reply); |
| 149 | BufferHeap buffer; |
| 150 | buffer.w = data.readInt32(); |
| 151 | buffer.h = data.readInt32(); |
| 152 | buffer.hor_stride = data.readInt32(); |
| 153 | buffer.ver_stride= data.readInt32(); |
| 154 | buffer.format = data.readInt32(); |
| 155 | buffer.transform = data.readInt32(); |
| 156 | buffer.flags = data.readInt32(); |
| 157 | buffer.heap = interface_cast<IMemoryHeap>(data.readStrongBinder()); |
| 158 | status_t err = registerBuffers(buffer); |
| 159 | reply->writeInt32(err); |
| 160 | return NO_ERROR; |
| 161 | } break; |
| 162 | case UNREGISTER_BUFFERS: { |
| 163 | CHECK_INTERFACE(ISurface, data, reply); |
| 164 | unregisterBuffers(); |
| 165 | return NO_ERROR; |
| 166 | } break; |
| 167 | case POST_BUFFER: { |
| 168 | CHECK_INTERFACE(ISurface, data, reply); |
| 169 | ssize_t offset = data.readInt32(); |
| 170 | postBuffer(offset); |
| 171 | return NO_ERROR; |
| 172 | } break; |
| 173 | case CREATE_OVERLAY: { |
| 174 | CHECK_INTERFACE(ISurface, data, reply); |
| 175 | int w = data.readInt32(); |
| 176 | int h = data.readInt32(); |
| 177 | int f = data.readInt32(); |
| 178 | sp<OverlayRef> o = createOverlay(w, h, f); |
| 179 | return OverlayRef::writeToParcel(reply, o); |
| 180 | } break; |
| 181 | default: |
| 182 | return BBinder::onTransact(code, data, reply, flags); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | }; // namespace android |