The Android Open Source Project | 9066cfe | 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 | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 17 | #define LOG_TAG "ISurface" |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Mathias Agopian | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/Parcel.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 25 | #include <ui/GraphicBuffer.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 27 | #include <surfaceflinger/Surface.h> |
| 28 | #include <surfaceflinger/ISurface.h> |
| 29 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | namespace android { |
| 31 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 32 | // ---------------------------------------------------------------------- |
| 33 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | class BpSurface : public BpInterface<ISurface> |
| 35 | { |
| 36 | public: |
| 37 | BpSurface(const sp<IBinder>& impl) |
| 38 | : BpInterface<ISurface>(impl) |
| 39 | { |
| 40 | } |
| 41 | |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 42 | virtual sp<GraphicBuffer> requestBuffer(int bufferIdx, |
| 43 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 44 | { |
| 45 | Parcel data, reply; |
| 46 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 47 | data.writeInt32(bufferIdx); |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 48 | data.writeInt32(w); |
| 49 | data.writeInt32(h); |
| 50 | data.writeInt32(format); |
Mathias Agopian | 5cec474 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 51 | data.writeInt32(usage); |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 52 | remote()->transact(REQUEST_BUFFER, data, &reply); |
Mathias Agopian | c86727f | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 53 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 54 | reply.read(*buffer); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 55 | return buffer; |
| 56 | } |
| 57 | |
Mathias Agopian | 59751db | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 58 | virtual status_t setBufferCount(int bufferCount) |
| 59 | { |
| 60 | Parcel data, reply; |
| 61 | data.writeInterfaceToken(ISurface::getInterfaceDescriptor()); |
| 62 | data.writeInt32(bufferCount); |
| 63 | remote()->transact(SET_BUFFER_COUNT, data, &reply); |
| 64 | status_t err = reply.readInt32(); |
| 65 | return err; |
| 66 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | IMPLEMENT_META_INTERFACE(Surface, "android.ui.ISurface"); |
| 70 | |
| 71 | // ---------------------------------------------------------------------- |
| 72 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | status_t BnSurface::onTransact( |
| 74 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 75 | { |
| 76 | switch(code) { |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 77 | case REQUEST_BUFFER: { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 78 | CHECK_INTERFACE(ISurface, data, reply); |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 79 | int bufferIdx = data.readInt32(); |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 80 | uint32_t w = data.readInt32(); |
| 81 | uint32_t h = data.readInt32(); |
| 82 | uint32_t format = data.readInt32(); |
| 83 | uint32_t usage = data.readInt32(); |
| 84 | sp<GraphicBuffer> buffer(requestBuffer(bufferIdx, w, h, format, usage)); |
Mathias Agopian | c86727f | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 85 | if (buffer == NULL) |
| 86 | return BAD_VALUE; |
| 87 | return reply->write(*buffer); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 88 | } |
Mathias Agopian | 59751db | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 89 | case SET_BUFFER_COUNT: { |
| 90 | CHECK_INTERFACE(ISurface, data, reply); |
| 91 | int bufferCount = data.readInt32(); |
| 92 | status_t err = setBufferCount(bufferCount); |
| 93 | reply->writeInt32(err); |
| 94 | return NO_ERROR; |
| 95 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | default: |
| 97 | return BBinder::onTransact(code, data, reply, flags); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | }; // namespace android |