2010-12-20 19:27:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/RefBase.h>
|
|
|
|
#include <utils/Vector.h>
|
|
|
|
#include <utils/Timers.h>
|
|
|
|
|
|
|
|
#include <binder/Parcel.h>
|
|
|
|
#include <binder/IInterface.h>
|
|
|
|
|
|
|
|
#include <gui/ISurfaceTexture.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum {
|
|
|
|
REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
|
|
|
|
SET_BUFFER_COUNT,
|
|
|
|
DEQUEUE_BUFFER,
|
|
|
|
QUEUE_BUFFER,
|
|
|
|
CANCEL_BUFFER,
|
|
|
|
SET_CROP,
|
|
|
|
SET_TRANSFORM,
|
2011-02-02 23:31:47 +00:00
|
|
|
GET_ALLOCATOR,
|
2011-04-20 21:20:59 +00:00
|
|
|
QUERY,
|
2011-05-03 02:51:12 +00:00
|
|
|
SET_SYNCHRONOUS_MODE,
|
2011-07-14 02:12:20 +00:00
|
|
|
CONNECT,
|
|
|
|
DISCONNECT,
|
2010-12-20 19:27:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BpSurfaceTexture : public BpInterface<ISurfaceTexture>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BpSurfaceTexture(const sp<IBinder>& impl)
|
|
|
|
: BpInterface<ISurfaceTexture>(impl)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-26 03:22:14 +00:00
|
|
|
virtual sp<GraphicBuffer> requestBuffer(int bufferIdx) {
|
2010-12-20 19:27:26 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(bufferIdx);
|
|
|
|
remote()->transact(REQUEST_BUFFER, data, &reply);
|
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
bool nonNull = reply.readInt32();
|
|
|
|
if (nonNull) {
|
|
|
|
buffer = new GraphicBuffer();
|
|
|
|
reply.read(*buffer);
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual status_t setBufferCount(int bufferCount)
|
|
|
|
{
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(bufferCount);
|
|
|
|
remote()->transact(SET_BUFFER_COUNT, data, &reply);
|
|
|
|
status_t err = reply.readInt32();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-04-26 03:22:14 +00:00
|
|
|
virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h,
|
|
|
|
uint32_t format, uint32_t usage) {
|
2010-12-20 19:27:26 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
2011-04-26 03:22:14 +00:00
|
|
|
data.writeInt32(w);
|
|
|
|
data.writeInt32(h);
|
|
|
|
data.writeInt32(format);
|
|
|
|
data.writeInt32(usage);
|
2010-12-20 19:27:26 +00:00
|
|
|
remote()->transact(DEQUEUE_BUFFER, data, &reply);
|
|
|
|
*buf = reply.readInt32();
|
|
|
|
int result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-02-18 19:02:42 +00:00
|
|
|
virtual status_t queueBuffer(int buf, int64_t timestamp) {
|
2010-12-20 19:27:26 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(buf);
|
2011-02-18 19:02:42 +00:00
|
|
|
data.writeInt64(timestamp);
|
2010-12-20 19:27:26 +00:00
|
|
|
remote()->transact(QUEUE_BUFFER, data, &reply);
|
|
|
|
status_t result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void cancelBuffer(int buf) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(buf);
|
|
|
|
remote()->transact(CANCEL_BUFFER, data, &reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual status_t setCrop(const Rect& reg) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeFloat(reg.left);
|
|
|
|
data.writeFloat(reg.top);
|
|
|
|
data.writeFloat(reg.right);
|
|
|
|
data.writeFloat(reg.bottom);
|
|
|
|
remote()->transact(SET_CROP, data, &reply);
|
|
|
|
status_t result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual status_t setTransform(uint32_t transform) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(transform);
|
|
|
|
remote()->transact(SET_TRANSFORM, data, &reply);
|
|
|
|
status_t result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
2011-02-02 23:31:47 +00:00
|
|
|
|
|
|
|
virtual sp<IBinder> getAllocator() {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
remote()->transact(GET_ALLOCATOR, data, &reply);
|
|
|
|
return reply.readStrongBinder();
|
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
|
|
|
|
virtual int query(int what, int* value) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(what);
|
|
|
|
remote()->transact(QUERY, data, &reply);
|
|
|
|
value[0] = reply.readInt32();
|
|
|
|
status_t result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-05-03 02:51:12 +00:00
|
|
|
virtual status_t setSynchronousMode(bool enabled) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(enabled);
|
|
|
|
remote()->transact(SET_SYNCHRONOUS_MODE, data, &reply);
|
|
|
|
status_t result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-07-14 02:12:20 +00:00
|
|
|
virtual status_t connect(int api) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(api);
|
|
|
|
remote()->transact(CONNECT, data, &reply);
|
|
|
|
status_t result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
2011-05-03 02:51:12 +00:00
|
|
|
|
2011-07-14 02:12:20 +00:00
|
|
|
virtual status_t disconnect(int api) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(api);
|
|
|
|
remote()->transact(DISCONNECT, data, &reply);
|
|
|
|
status_t result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_META_INTERFACE(SurfaceTexture, "android.gui.SurfaceTexture");
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t BnSurfaceTexture::onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
|
|
|
|
{
|
|
|
|
switch(code) {
|
|
|
|
case REQUEST_BUFFER: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
int bufferIdx = data.readInt32();
|
2011-04-26 03:22:14 +00:00
|
|
|
sp<GraphicBuffer> buffer(requestBuffer(bufferIdx));
|
2010-12-20 19:27:26 +00:00
|
|
|
reply->writeInt32(buffer != 0);
|
|
|
|
if (buffer != 0) {
|
|
|
|
reply->write(*buffer);
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case SET_BUFFER_COUNT: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
int bufferCount = data.readInt32();
|
|
|
|
int result = setBufferCount(bufferCount);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case DEQUEUE_BUFFER: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
2011-04-26 03:22:14 +00:00
|
|
|
uint32_t w = data.readInt32();
|
|
|
|
uint32_t h = data.readInt32();
|
|
|
|
uint32_t format = data.readInt32();
|
|
|
|
uint32_t usage = data.readInt32();
|
2010-12-20 19:27:26 +00:00
|
|
|
int buf;
|
2011-04-26 03:22:14 +00:00
|
|
|
int result = dequeueBuffer(&buf, w, h, format, usage);
|
2010-12-20 19:27:26 +00:00
|
|
|
reply->writeInt32(buf);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case QUEUE_BUFFER: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
int buf = data.readInt32();
|
2011-02-18 19:02:42 +00:00
|
|
|
int64_t timestamp = data.readInt64();
|
|
|
|
status_t result = queueBuffer(buf, timestamp);
|
2010-12-20 19:27:26 +00:00
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case CANCEL_BUFFER: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
int buf = data.readInt32();
|
|
|
|
cancelBuffer(buf);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case SET_CROP: {
|
|
|
|
Rect reg;
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
reg.left = data.readFloat();
|
|
|
|
reg.top = data.readFloat();
|
|
|
|
reg.right = data.readFloat();
|
|
|
|
reg.bottom = data.readFloat();
|
|
|
|
status_t result = setCrop(reg);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case SET_TRANSFORM: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
uint32_t transform = data.readInt32();
|
|
|
|
status_t result = setTransform(transform);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2011-02-02 23:31:47 +00:00
|
|
|
case GET_ALLOCATOR: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
sp<IBinder> result = getAllocator();
|
|
|
|
reply->writeStrongBinder(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2011-04-20 21:20:59 +00:00
|
|
|
case QUERY: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
int value;
|
|
|
|
int what = data.readInt32();
|
|
|
|
int res = query(what, &value);
|
|
|
|
reply->writeInt32(value);
|
|
|
|
reply->writeInt32(res);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2011-05-03 02:51:12 +00:00
|
|
|
case SET_SYNCHRONOUS_MODE: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
bool enabled = data.readInt32();
|
|
|
|
status_t res = setSynchronousMode(enabled);
|
|
|
|
reply->writeInt32(res);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2011-07-14 02:12:20 +00:00
|
|
|
case CONNECT: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
int api = data.readInt32();
|
|
|
|
status_t res = connect(api);
|
|
|
|
reply->writeInt32(res);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case DISCONNECT: {
|
|
|
|
CHECK_INTERFACE(ISurfaceTexture, data, reply);
|
|
|
|
int api = data.readInt32();
|
|
|
|
status_t res = connect(api);
|
|
|
|
reply->writeInt32(res);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
return BBinder::onTransact(code, data, reply, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|