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>
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
#include <gui/IGraphicBufferProducer.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum {
|
|
|
|
REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
|
|
|
|
SET_BUFFER_COUNT,
|
|
|
|
DEQUEUE_BUFFER,
|
|
|
|
QUEUE_BUFFER,
|
|
|
|
CANCEL_BUFFER,
|
2011-04-20 21:20:59 +00:00
|
|
|
QUERY,
|
2011-07-14 02:12:20 +00:00
|
|
|
CONNECT,
|
|
|
|
DISCONNECT,
|
2010-12-20 19:27:26 +00:00
|
|
|
};
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
|
2010-12-20 19:27:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-12-18 17:49:45 +00:00
|
|
|
BpGraphicBufferProducer(const sp<IBinder>& impl)
|
|
|
|
: BpInterface<IGraphicBufferProducer>(impl)
|
2010-12-20 19:27:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-07-19 19:08:33 +00:00
|
|
|
virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
|
2010-12-20 19:27:26 +00:00
|
|
|
Parcel data, reply;
|
2012-12-18 17:49:45 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
2010-12-20 19:27:26 +00:00
|
|
|
data.writeInt32(bufferIdx);
|
2011-10-14 22:03:17 +00:00
|
|
|
status_t result =remote()->transact(REQUEST_BUFFER, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
bool nonNull = reply.readInt32();
|
|
|
|
if (nonNull) {
|
2011-07-19 19:08:33 +00:00
|
|
|
*buf = new GraphicBuffer();
|
|
|
|
reply.read(**buf);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
2011-10-14 22:03:17 +00:00
|
|
|
result = reply.readInt32();
|
2011-07-19 19:08:33 +00:00
|
|
|
return result;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual status_t setBufferCount(int bufferCount)
|
|
|
|
{
|
|
|
|
Parcel data, reply;
|
2012-12-18 17:49:45 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
2010-12-20 19:27:26 +00:00
|
|
|
data.writeInt32(bufferCount);
|
2011-10-14 22:03:17 +00:00
|
|
|
status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = reply.readInt32();
|
|
|
|
return result;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 05:10:56 +00:00
|
|
|
virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async,
|
2012-06-14 22:26:33 +00:00
|
|
|
uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
|
2010-12-20 19:27:26 +00:00
|
|
|
Parcel data, reply;
|
2012-12-18 17:49:45 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
2013-07-19 05:10:56 +00:00
|
|
|
data.writeInt32(async);
|
2011-04-26 03:22:14 +00:00
|
|
|
data.writeInt32(w);
|
|
|
|
data.writeInt32(h);
|
|
|
|
data.writeInt32(format);
|
|
|
|
data.writeInt32(usage);
|
2011-10-14 22:03:17 +00:00
|
|
|
status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
*buf = reply.readInt32();
|
2013-08-01 22:48:40 +00:00
|
|
|
bool nonNull = reply.readInt32();
|
|
|
|
if (nonNull) {
|
2013-03-16 04:34:30 +00:00
|
|
|
*fence = new Fence();
|
2013-08-01 22:48:40 +00:00
|
|
|
reply.read(**fence);
|
2012-06-14 22:26:33 +00:00
|
|
|
}
|
2011-10-14 22:03:17 +00:00
|
|
|
result = reply.readInt32();
|
2010-12-20 19:27:26 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-04-09 23:14:01 +00:00
|
|
|
virtual status_t queueBuffer(int buf,
|
|
|
|
const QueueBufferInput& input, QueueBufferOutput* output) {
|
2010-12-20 19:27:26 +00:00
|
|
|
Parcel data, reply;
|
2012-12-18 17:49:45 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
2010-12-20 19:27:26 +00:00
|
|
|
data.writeInt32(buf);
|
2012-06-28 19:52:05 +00:00
|
|
|
data.write(input);
|
2011-10-14 22:03:17 +00:00
|
|
|
status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
2012-04-09 23:14:01 +00:00
|
|
|
memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
|
2011-10-14 22:03:17 +00:00
|
|
|
result = reply.readInt32();
|
2010-12-20 19:27:26 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-16 04:34:30 +00:00
|
|
|
virtual void cancelBuffer(int buf, const sp<Fence>& fence) {
|
2010-12-20 19:27:26 +00:00
|
|
|
Parcel data, reply;
|
2012-12-18 17:49:45 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
2010-12-20 19:27:26 +00:00
|
|
|
data.writeInt32(buf);
|
2012-12-20 22:05:45 +00:00
|
|
|
data.write(*fence.get());
|
2010-12-20 19:27:26 +00:00
|
|
|
remote()->transact(CANCEL_BUFFER, data, &reply);
|
|
|
|
}
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
virtual int query(int what, int* value) {
|
|
|
|
Parcel data, reply;
|
2012-12-18 17:49:45 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
2011-04-20 21:20:59 +00:00
|
|
|
data.writeInt32(what);
|
2011-10-14 22:03:17 +00:00
|
|
|
status_t result = remote()->transact(QUERY, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
value[0] = reply.readInt32();
|
2011-10-14 22:03:17 +00:00
|
|
|
result = reply.readInt32();
|
2011-04-20 21:20:59 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-12 02:35:45 +00:00
|
|
|
virtual status_t connect(const sp<IBinder>& token,
|
|
|
|
int api, bool producerControlledByApp, QueueBufferOutput* output) {
|
2011-07-14 02:12:20 +00:00
|
|
|
Parcel data, reply;
|
2012-12-18 17:49:45 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
2013-09-12 02:35:45 +00:00
|
|
|
data.writeStrongBinder(token);
|
2011-07-14 02:12:20 +00:00
|
|
|
data.writeInt32(api);
|
2013-07-17 05:56:09 +00:00
|
|
|
data.writeInt32(producerControlledByApp);
|
2011-10-14 22:03:17 +00:00
|
|
|
status_t result = remote()->transact(CONNECT, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
2012-04-23 21:28:58 +00:00
|
|
|
memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
|
2011-10-14 22:03:17 +00:00
|
|
|
result = reply.readInt32();
|
2011-07-14 02:12:20 +00:00
|
|
|
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;
|
2012-12-18 17:49:45 +00:00
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
2011-07-14 02:12:20 +00:00
|
|
|
data.writeInt32(api);
|
2011-10-14 22:03:17 +00:00
|
|
|
status_t result =remote()->transact(DISCONNECT, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = reply.readInt32();
|
2011-07-14 02:12:20 +00:00
|
|
|
return result;
|
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
};
|
|
|
|
|
2013-01-08 19:25:51 +00:00
|
|
|
IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
status_t BnGraphicBufferProducer::onTransact(
|
2010-12-20 19:27:26 +00:00
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
|
|
|
|
{
|
|
|
|
switch(code) {
|
|
|
|
case REQUEST_BUFFER: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2010-12-20 19:27:26 +00:00
|
|
|
int bufferIdx = data.readInt32();
|
2011-07-19 19:08:33 +00:00
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
int result = requestBuffer(bufferIdx, &buffer);
|
2010-12-20 19:27:26 +00:00
|
|
|
reply->writeInt32(buffer != 0);
|
|
|
|
if (buffer != 0) {
|
|
|
|
reply->write(*buffer);
|
|
|
|
}
|
2011-07-19 19:08:33 +00:00
|
|
|
reply->writeInt32(result);
|
2010-12-20 19:27:26 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case SET_BUFFER_COUNT: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2010-12-20 19:27:26 +00:00
|
|
|
int bufferCount = data.readInt32();
|
|
|
|
int result = setBufferCount(bufferCount);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case DEQUEUE_BUFFER: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2013-07-19 05:10:56 +00:00
|
|
|
bool async = data.readInt32();
|
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;
|
2012-06-14 22:26:33 +00:00
|
|
|
sp<Fence> fence;
|
2013-07-19 05:10:56 +00:00
|
|
|
int result = dequeueBuffer(&buf, &fence, async, w, h, format, usage);
|
2010-12-20 19:27:26 +00:00
|
|
|
reply->writeInt32(buf);
|
2012-12-20 22:05:45 +00:00
|
|
|
reply->writeInt32(fence != NULL);
|
|
|
|
if (fence != NULL) {
|
2013-08-01 22:48:40 +00:00
|
|
|
reply->write(*fence);
|
2012-06-14 22:26:33 +00:00
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case QUEUE_BUFFER: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2010-12-20 19:27:26 +00:00
|
|
|
int buf = data.readInt32();
|
2012-06-28 19:52:05 +00:00
|
|
|
QueueBufferInput input(data);
|
2012-04-09 23:14:01 +00:00
|
|
|
QueueBufferOutput* const output =
|
|
|
|
reinterpret_cast<QueueBufferOutput *>(
|
|
|
|
reply->writeInplace(sizeof(QueueBufferOutput)));
|
2012-06-28 19:52:05 +00:00
|
|
|
status_t result = queueBuffer(buf, input, output);
|
2010-12-20 19:27:26 +00:00
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case CANCEL_BUFFER: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2010-12-20 19:27:26 +00:00
|
|
|
int buf = data.readInt32();
|
2012-12-20 22:05:45 +00:00
|
|
|
sp<Fence> fence = new Fence();
|
|
|
|
data.read(*fence.get());
|
2012-06-28 19:52:05 +00:00
|
|
|
cancelBuffer(buf, fence);
|
2010-12-20 19:27:26 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2011-04-20 21:20:59 +00:00
|
|
|
case QUERY: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2011-04-20 21:20:59 +00:00
|
|
|
int value;
|
|
|
|
int what = data.readInt32();
|
|
|
|
int res = query(what, &value);
|
|
|
|
reply->writeInt32(value);
|
|
|
|
reply->writeInt32(res);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2011-07-14 02:12:20 +00:00
|
|
|
case CONNECT: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2013-09-12 02:35:45 +00:00
|
|
|
sp<IBinder> token = data.readStrongBinder();
|
2011-07-14 02:12:20 +00:00
|
|
|
int api = data.readInt32();
|
2013-07-17 05:56:09 +00:00
|
|
|
bool producerControlledByApp = data.readInt32();
|
2012-04-23 21:28:58 +00:00
|
|
|
QueueBufferOutput* const output =
|
|
|
|
reinterpret_cast<QueueBufferOutput *>(
|
|
|
|
reply->writeInplace(sizeof(QueueBufferOutput)));
|
2013-09-12 02:35:45 +00:00
|
|
|
status_t res = connect(token, api, producerControlledByApp, output);
|
2011-07-14 02:12:20 +00:00
|
|
|
reply->writeInt32(res);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case DISCONNECT: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2011-07-14 02:12:20 +00:00
|
|
|
int api = data.readInt32();
|
2011-07-15 03:20:58 +00:00
|
|
|
status_t res = disconnect(api);
|
2011-07-14 02:12:20 +00:00
|
|
|
reply->writeInt32(res);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
return BBinder::onTransact(code, data, reply, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) {
|
2012-06-28 19:52:05 +00:00
|
|
|
parcel.read(*this);
|
|
|
|
}
|
|
|
|
|
2013-07-30 04:24:40 +00:00
|
|
|
size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const {
|
2012-06-28 19:52:05 +00:00
|
|
|
return sizeof(timestamp)
|
2013-08-16 21:55:39 +00:00
|
|
|
+ sizeof(isAutoTimestamp)
|
2012-06-28 19:52:05 +00:00
|
|
|
+ sizeof(crop)
|
|
|
|
+ sizeof(scalingMode)
|
|
|
|
+ sizeof(transform)
|
2013-07-19 05:10:56 +00:00
|
|
|
+ sizeof(async)
|
2012-12-20 22:05:45 +00:00
|
|
|
+ fence->getFlattenedSize();
|
2012-06-28 19:52:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 04:24:40 +00:00
|
|
|
size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const {
|
2012-12-20 22:05:45 +00:00
|
|
|
return fence->getFdCount();
|
2012-06-28 19:52:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 04:24:40 +00:00
|
|
|
status_t IGraphicBufferProducer::QueueBufferInput::flatten(
|
|
|
|
void*& buffer, size_t& size, int*& fds, size_t& count) const
|
2012-06-28 19:52:05 +00:00
|
|
|
{
|
2013-07-30 04:24:40 +00:00
|
|
|
if (size < getFlattenedSize()) {
|
|
|
|
return NO_MEMORY;
|
|
|
|
}
|
|
|
|
FlattenableUtils::write(buffer, size, timestamp);
|
2013-08-16 21:55:39 +00:00
|
|
|
FlattenableUtils::write(buffer, size, isAutoTimestamp);
|
2013-07-30 04:24:40 +00:00
|
|
|
FlattenableUtils::write(buffer, size, crop);
|
|
|
|
FlattenableUtils::write(buffer, size, scalingMode);
|
|
|
|
FlattenableUtils::write(buffer, size, transform);
|
|
|
|
FlattenableUtils::write(buffer, size, async);
|
|
|
|
return fence->flatten(buffer, size, fds, count);
|
2012-06-28 19:52:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 04:24:40 +00:00
|
|
|
status_t IGraphicBufferProducer::QueueBufferInput::unflatten(
|
|
|
|
void const*& buffer, size_t& size, int const*& fds, size_t& count)
|
2012-06-28 19:52:05 +00:00
|
|
|
{
|
2013-07-30 04:24:40 +00:00
|
|
|
size_t minNeeded =
|
|
|
|
sizeof(timestamp)
|
2013-08-16 21:55:39 +00:00
|
|
|
+ sizeof(isAutoTimestamp)
|
2013-07-30 04:24:40 +00:00
|
|
|
+ sizeof(crop)
|
|
|
|
+ sizeof(scalingMode)
|
|
|
|
+ sizeof(transform)
|
|
|
|
+ sizeof(async);
|
|
|
|
|
|
|
|
if (size < minNeeded) {
|
|
|
|
return NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
FlattenableUtils::read(buffer, size, timestamp);
|
2013-08-16 21:55:39 +00:00
|
|
|
FlattenableUtils::read(buffer, size, isAutoTimestamp);
|
2013-07-30 04:24:40 +00:00
|
|
|
FlattenableUtils::read(buffer, size, crop);
|
|
|
|
FlattenableUtils::read(buffer, size, scalingMode);
|
|
|
|
FlattenableUtils::read(buffer, size, transform);
|
|
|
|
FlattenableUtils::read(buffer, size, async);
|
|
|
|
|
2012-12-20 22:05:45 +00:00
|
|
|
fence = new Fence();
|
2013-07-30 04:24:40 +00:00
|
|
|
return fence->unflatten(buffer, size, fds, count);
|
2012-06-28 19:52:05 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
}; // namespace android
|