blob: bc14ad55149c0f3aa89f6cd82b36562f459c7c49 [file] [log] [blame]
Jamie Gennis8ba32fa2010-12-20 11:27:26 -08001/*
2 * Copyright (C) 2010 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 <stdint.h>
18#include <sys/types.h>
19
20#include <utils/Errors.h>
21#include <utils/RefBase.h>
22#include <utils/Vector.h>
23#include <utils/Timers.h>
24
25#include <binder/Parcel.h>
26#include <binder/IInterface.h>
27
28#include <gui/ISurfaceTexture.h>
29
30namespace android {
31// ----------------------------------------------------------------------------
32
33enum {
34 REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
35 SET_BUFFER_COUNT,
36 DEQUEUE_BUFFER,
37 QUEUE_BUFFER,
38 CANCEL_BUFFER,
39 SET_CROP,
40 SET_TRANSFORM,
Jamie Gennis1b20cde2011-02-02 15:31:47 -080041 GET_ALLOCATOR,
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080042};
43
44
45class BpSurfaceTexture : public BpInterface<ISurfaceTexture>
46{
47public:
48 BpSurfaceTexture(const sp<IBinder>& impl)
49 : BpInterface<ISurfaceTexture>(impl)
50 {
51 }
52
53 virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
54 uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
55 Parcel data, reply;
56 data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
57 data.writeInt32(bufferIdx);
58 data.writeInt32(w);
59 data.writeInt32(h);
60 data.writeInt32(format);
61 data.writeInt32(usage);
62 remote()->transact(REQUEST_BUFFER, data, &reply);
63 sp<GraphicBuffer> buffer;
64 bool nonNull = reply.readInt32();
65 if (nonNull) {
66 buffer = new GraphicBuffer();
67 reply.read(*buffer);
68 }
69 return buffer;
70 }
71
72 virtual status_t setBufferCount(int bufferCount)
73 {
74 Parcel data, reply;
75 data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
76 data.writeInt32(bufferCount);
77 remote()->transact(SET_BUFFER_COUNT, data, &reply);
78 status_t err = reply.readInt32();
79 return err;
80 }
81
82 virtual status_t dequeueBuffer(int *buf) {
83 Parcel data, reply;
84 data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
85 remote()->transact(DEQUEUE_BUFFER, data, &reply);
86 *buf = reply.readInt32();
87 int result = reply.readInt32();
88 return result;
89 }
90
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080091 virtual status_t queueBuffer(int buf, int64_t timestamp) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080092 Parcel data, reply;
93 data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
94 data.writeInt32(buf);
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -080095 data.writeInt64(timestamp);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080096 remote()->transact(QUEUE_BUFFER, data, &reply);
97 status_t result = reply.readInt32();
98 return result;
99 }
100
101 virtual void cancelBuffer(int buf) {
102 Parcel data, reply;
103 data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
104 data.writeInt32(buf);
105 remote()->transact(CANCEL_BUFFER, data, &reply);
106 }
107
108 virtual status_t setCrop(const Rect& reg) {
109 Parcel data, reply;
110 data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
111 data.writeFloat(reg.left);
112 data.writeFloat(reg.top);
113 data.writeFloat(reg.right);
114 data.writeFloat(reg.bottom);
115 remote()->transact(SET_CROP, data, &reply);
116 status_t result = reply.readInt32();
117 return result;
118 }
119
120 virtual status_t setTransform(uint32_t transform) {
121 Parcel data, reply;
122 data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
123 data.writeInt32(transform);
124 remote()->transact(SET_TRANSFORM, data, &reply);
125 status_t result = reply.readInt32();
126 return result;
127 }
Jamie Gennis1b20cde2011-02-02 15:31:47 -0800128
129 virtual sp<IBinder> getAllocator() {
130 Parcel data, reply;
131 data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
132 remote()->transact(GET_ALLOCATOR, data, &reply);
133 return reply.readStrongBinder();
134 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800135};
136
137IMPLEMENT_META_INTERFACE(SurfaceTexture, "android.gui.SurfaceTexture");
138
139// ----------------------------------------------------------------------
140
141status_t BnSurfaceTexture::onTransact(
142 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
143{
144 switch(code) {
145 case REQUEST_BUFFER: {
146 CHECK_INTERFACE(ISurfaceTexture, data, reply);
147 int bufferIdx = data.readInt32();
148 uint32_t w = data.readInt32();
149 uint32_t h = data.readInt32();
150 uint32_t format = data.readInt32();
151 uint32_t usage = data.readInt32();
152 sp<GraphicBuffer> buffer(requestBuffer(bufferIdx, w, h, format,
153 usage));
154 reply->writeInt32(buffer != 0);
155 if (buffer != 0) {
156 reply->write(*buffer);
157 }
158 return NO_ERROR;
159 } break;
160 case SET_BUFFER_COUNT: {
161 CHECK_INTERFACE(ISurfaceTexture, data, reply);
162 int bufferCount = data.readInt32();
163 int result = setBufferCount(bufferCount);
164 reply->writeInt32(result);
165 return NO_ERROR;
166 } break;
167 case DEQUEUE_BUFFER: {
168 CHECK_INTERFACE(ISurfaceTexture, data, reply);
169 int buf;
170 int result = dequeueBuffer(&buf);
171 reply->writeInt32(buf);
172 reply->writeInt32(result);
173 return NO_ERROR;
174 } break;
175 case QUEUE_BUFFER: {
176 CHECK_INTERFACE(ISurfaceTexture, data, reply);
177 int buf = data.readInt32();
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800178 int64_t timestamp = data.readInt64();
179 status_t result = queueBuffer(buf, timestamp);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800180 reply->writeInt32(result);
181 return NO_ERROR;
182 } break;
183 case CANCEL_BUFFER: {
184 CHECK_INTERFACE(ISurfaceTexture, data, reply);
185 int buf = data.readInt32();
186 cancelBuffer(buf);
187 return NO_ERROR;
188 } break;
189 case SET_CROP: {
190 Rect reg;
191 CHECK_INTERFACE(ISurfaceTexture, data, reply);
192 reg.left = data.readFloat();
193 reg.top = data.readFloat();
194 reg.right = data.readFloat();
195 reg.bottom = data.readFloat();
196 status_t result = setCrop(reg);
197 reply->writeInt32(result);
198 return NO_ERROR;
199 } break;
200 case SET_TRANSFORM: {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800201 CHECK_INTERFACE(ISurfaceTexture, data, reply);
202 uint32_t transform = data.readInt32();
203 status_t result = setTransform(transform);
204 reply->writeInt32(result);
205 return NO_ERROR;
206 } break;
Jamie Gennis1b20cde2011-02-02 15:31:47 -0800207 case GET_ALLOCATOR: {
208 CHECK_INTERFACE(ISurfaceTexture, data, reply);
209 sp<IBinder> result = getAllocator();
210 reply->writeStrongBinder(result);
211 return NO_ERROR;
212 } break;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800213 }
214 return BBinder::onTransact(code, data, reply, flags);
215}
216
217// ----------------------------------------------------------------------------
218
219}; // namespace android