blob: 23b90af311431fc73af52c5eed138bcc6bc7a01e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Agopian1473f462009-04-10 14:24:30 -070017#define LOG_TAG "ISurface"
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019#include <stdio.h>
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopian07952722009-05-19 19:08:10 -070023#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
Mathias Agopian6950e422009-10-05 17:07:12 -070025#include <ui/GraphicBuffer.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
Mathias Agopian000479f2010-02-09 17:46:37 -080027#include <surfaceflinger/Surface.h>
28#include <surfaceflinger/ISurface.h>
29
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030namespace android {
31
Mathias Agopian1473f462009-04-10 14:24:30 -070032// ----------------------------------------------------------------------
33
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034class BpSurface : public BpInterface<ISurface>
35{
36public:
37 BpSurface(const sp<IBinder>& impl)
38 : BpInterface<ISurface>(impl)
39 {
40 }
41
Mathias Agopian2be352a2010-05-21 17:24:35 -070042 virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
43 uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
Mathias Agopian1473f462009-04-10 14:24:30 -070044 {
45 Parcel data, reply;
46 data.writeInterfaceToken(ISurface::getInterfaceDescriptor());
Mathias Agopian9779b222009-09-07 16:32:45 -070047 data.writeInt32(bufferIdx);
Mathias Agopian2be352a2010-05-21 17:24:35 -070048 data.writeInt32(w);
49 data.writeInt32(h);
50 data.writeInt32(format);
Mathias Agopian5cec4742009-08-11 22:34:02 -070051 data.writeInt32(usage);
Mathias Agopian9779b222009-09-07 16:32:45 -070052 remote()->transact(REQUEST_BUFFER, data, &reply);
Mathias Agopianc86727f2010-02-11 17:30:52 -080053 sp<GraphicBuffer> buffer = new GraphicBuffer();
54 reply.read(*buffer);
Mathias Agopian1473f462009-04-10 14:24:30 -070055 return buffer;
56 }
57
Mathias Agopian59751db2010-05-07 15:58:44 -070058 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 Project9066cfe2009-03-03 19:31:44 -080067};
68
69IMPLEMENT_META_INTERFACE(Surface, "android.ui.ISurface");
70
71// ----------------------------------------------------------------------
72
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073status_t BnSurface::onTransact(
74 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
75{
76 switch(code) {
Mathias Agopian9779b222009-09-07 16:32:45 -070077 case REQUEST_BUFFER: {
Mathias Agopian1473f462009-04-10 14:24:30 -070078 CHECK_INTERFACE(ISurface, data, reply);
Mathias Agopian9779b222009-09-07 16:32:45 -070079 int bufferIdx = data.readInt32();
Mathias Agopian2be352a2010-05-21 17:24:35 -070080 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 Agopianc86727f2010-02-11 17:30:52 -080085 if (buffer == NULL)
86 return BAD_VALUE;
87 return reply->write(*buffer);
Mathias Agopian1473f462009-04-10 14:24:30 -070088 }
Mathias Agopian59751db2010-05-07 15:58:44 -070089 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 Project9066cfe2009-03-03 19:31:44 -080096 default:
97 return BBinder::onTransact(code, data, reply, flags);
98 }
99}
100
101}; // namespace android