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>
|
2014-03-03 23:42:54 +00:00
|
|
|
#include <utils/NativeHandle.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
#include <utils/RefBase.h>
|
|
|
|
#include <utils/Timers.h>
|
2014-03-03 23:42:54 +00:00
|
|
|
#include <utils/Vector.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
#include <binder/Parcel.h>
|
|
|
|
#include <binder/IInterface.h>
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
#include <gui/IGraphicBufferProducer.h>
|
2014-03-21 20:05:51 +00:00
|
|
|
#include <gui/IProducerListener.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum {
|
|
|
|
REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
|
|
|
|
SET_BUFFER_COUNT,
|
|
|
|
DEQUEUE_BUFFER,
|
2014-03-06 23:14:33 +00:00
|
|
|
DETACH_BUFFER,
|
2014-03-28 22:25:31 +00:00
|
|
|
DETACH_NEXT_BUFFER,
|
2014-03-06 23:14:33 +00:00
|
|
|
ATTACH_BUFFER,
|
2010-12-20 19:27:26 +00:00
|
|
|
QUEUE_BUFFER,
|
|
|
|
CANCEL_BUFFER,
|
2011-04-20 21:20:59 +00:00
|
|
|
QUERY,
|
2011-07-14 02:12:20 +00:00
|
|
|
CONNECT,
|
|
|
|
DISCONNECT,
|
2014-03-03 23:42:54 +00:00
|
|
|
SET_SIDEBAND_STREAM,
|
2014-06-20 20:13:57 +00:00
|
|
|
ALLOCATE_BUFFERS,
|
2015-04-17 00:28:43 +00:00
|
|
|
ALLOW_ALLOCATION,
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-18 18:24:03 +00:00
|
|
|
virtual ~BpGraphicBufferProducer();
|
|
|
|
|
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();
|
2012-11-20 11:24:35 +00:00
|
|
|
result = reply.read(**buf);
|
|
|
|
if(result != NO_ERROR) {
|
|
|
|
(*buf).clear();
|
|
|
|
return result;
|
|
|
|
}
|
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,
|
2014-11-18 18:24:03 +00:00
|
|
|
uint32_t width, uint32_t height, PixelFormat 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());
|
2014-11-18 18:24:03 +00:00
|
|
|
data.writeInt32(static_cast<int32_t>(async));
|
|
|
|
data.writeUint32(width);
|
|
|
|
data.writeUint32(height);
|
|
|
|
data.writeInt32(static_cast<int32_t>(format));
|
|
|
|
data.writeUint32(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;
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
virtual status_t detachBuffer(int slot) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(slot);
|
|
|
|
status_t result = remote()->transact(DETACH_BUFFER, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-03-28 22:25:31 +00:00
|
|
|
virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
|
|
|
|
sp<Fence>* outFence) {
|
|
|
|
if (outBuffer == NULL) {
|
|
|
|
ALOGE("detachNextBuffer: outBuffer must not be NULL");
|
|
|
|
return BAD_VALUE;
|
|
|
|
} else if (outFence == NULL) {
|
|
|
|
ALOGE("detachNextBuffer: outFence must not be NULL");
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
|
|
|
status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = reply.readInt32();
|
|
|
|
if (result == NO_ERROR) {
|
|
|
|
bool nonNull = reply.readInt32();
|
|
|
|
if (nonNull) {
|
|
|
|
*outBuffer = new GraphicBuffer;
|
|
|
|
reply.read(**outBuffer);
|
|
|
|
}
|
|
|
|
nonNull = reply.readInt32();
|
|
|
|
if (nonNull) {
|
|
|
|
*outFence = new Fence;
|
|
|
|
reply.read(**outFence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-03-06 23:14:33 +00:00
|
|
|
virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
|
|
|
data.write(*buffer.get());
|
|
|
|
status_t result = remote()->transact(ATTACH_BUFFER, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
*slot = reply.readInt32();
|
|
|
|
result = reply.readInt32();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-21 20:05:51 +00:00
|
|
|
virtual status_t connect(const sp<IProducerListener>& listener,
|
2013-09-12 02:35:45 +00:00
|
|
|
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());
|
2014-03-21 20:05:51 +00:00
|
|
|
if (listener != NULL) {
|
|
|
|
data.writeInt32(1);
|
2014-11-14 16:01:01 +00:00
|
|
|
data.writeStrongBinder(IInterface::asBinder(listener));
|
2014-03-21 20:05:51 +00:00
|
|
|
} else {
|
|
|
|
data.writeInt32(0);
|
|
|
|
}
|
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;
|
|
|
|
}
|
2014-03-03 23:42:54 +00:00
|
|
|
|
|
|
|
virtual status_t setSidebandStream(const sp<NativeHandle>& stream) {
|
|
|
|
Parcel data, reply;
|
|
|
|
status_t result;
|
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
|
|
|
if (stream.get()) {
|
|
|
|
data.writeInt32(true);
|
|
|
|
data.writeNativeHandle(stream->handle());
|
|
|
|
} else {
|
|
|
|
data.writeInt32(false);
|
|
|
|
}
|
|
|
|
if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) {
|
|
|
|
result = reply.readInt32();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2014-06-20 20:13:57 +00:00
|
|
|
|
|
|
|
virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
|
2014-11-18 18:24:03 +00:00
|
|
|
PixelFormat format, uint32_t usage) {
|
2014-06-20 20:13:57 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(static_cast<int32_t>(async));
|
2014-11-18 18:24:03 +00:00
|
|
|
data.writeUint32(width);
|
|
|
|
data.writeUint32(height);
|
2014-06-20 20:13:57 +00:00
|
|
|
data.writeInt32(static_cast<int32_t>(format));
|
2014-11-18 18:24:03 +00:00
|
|
|
data.writeUint32(usage);
|
2014-06-20 20:13:57 +00:00
|
|
|
status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
ALOGE("allocateBuffers failed to transact: %d", result);
|
|
|
|
}
|
|
|
|
}
|
2015-04-17 00:28:43 +00:00
|
|
|
|
|
|
|
virtual status_t allowAllocation(bool allow) {
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(static_cast<int32_t>(allow));
|
|
|
|
status_t result = remote()->transact(ALLOW_ALLOCATION, data, &reply);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = reply.readInt32();
|
|
|
|
return result;
|
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
};
|
|
|
|
|
2014-11-18 18:24:03 +00:00
|
|
|
// Out-of-line virtual method definition to trigger vtable emission in this
|
|
|
|
// translation unit (see clang warning -Wweak-vtables)
|
|
|
|
BpGraphicBufferProducer::~BpGraphicBufferProducer() {}
|
|
|
|
|
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;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
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;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
case DEQUEUE_BUFFER: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2014-11-18 18:24:03 +00:00
|
|
|
bool async = static_cast<bool>(data.readInt32());
|
|
|
|
uint32_t width = data.readUint32();
|
|
|
|
uint32_t height = data.readUint32();
|
|
|
|
PixelFormat format = static_cast<PixelFormat>(data.readInt32());
|
|
|
|
uint32_t usage = data.readUint32();
|
2010-12-20 19:27:26 +00:00
|
|
|
int buf;
|
2012-06-14 22:26:33 +00:00
|
|
|
sp<Fence> fence;
|
2014-11-18 18:24:03 +00:00
|
|
|
int result = dequeueBuffer(&buf, &fence, async, width, height,
|
|
|
|
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);
|
2014-03-06 23:14:33 +00:00
|
|
|
return NO_ERROR;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2014-03-06 23:14:33 +00:00
|
|
|
case DETACH_BUFFER: {
|
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
|
|
|
int slot = data.readInt32();
|
|
|
|
int result = detachBuffer(slot);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2014-03-28 22:25:31 +00:00
|
|
|
case DETACH_NEXT_BUFFER: {
|
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
sp<Fence> fence;
|
|
|
|
int32_t result = detachNextBuffer(&buffer, &fence);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
if (result == NO_ERROR) {
|
|
|
|
reply->writeInt32(buffer != NULL);
|
|
|
|
if (buffer != NULL) {
|
|
|
|
reply->write(*buffer);
|
|
|
|
}
|
|
|
|
reply->writeInt32(fence != NULL);
|
|
|
|
if (fence != NULL) {
|
|
|
|
reply->write(*fence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2014-03-06 23:14:33 +00:00
|
|
|
case ATTACH_BUFFER: {
|
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
|
|
|
sp<GraphicBuffer> buffer = new GraphicBuffer();
|
|
|
|
data.read(*buffer.get());
|
|
|
|
int slot;
|
|
|
|
int result = attachBuffer(&slot, buffer);
|
|
|
|
reply->writeInt32(slot);
|
|
|
|
reply->writeInt32(result);
|
2010-12-20 19:27:26 +00:00
|
|
|
return NO_ERROR;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
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;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
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;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
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;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2011-07-14 02:12:20 +00:00
|
|
|
case CONNECT: {
|
2012-12-18 17:49:45 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
2014-03-21 20:05:51 +00:00
|
|
|
sp<IProducerListener> listener;
|
|
|
|
if (data.readInt32() == 1) {
|
|
|
|
listener = IProducerListener::asInterface(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)));
|
2014-03-21 20:05:51 +00:00
|
|
|
status_t res = connect(listener, api, producerControlledByApp, output);
|
2011-07-14 02:12:20 +00:00
|
|
|
reply->writeInt32(res);
|
|
|
|
return NO_ERROR;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2011-07-14 02:12:20 +00:00
|
|
|
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;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2014-03-03 23:42:54 +00:00
|
|
|
case SET_SIDEBAND_STREAM: {
|
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
|
|
|
sp<NativeHandle> stream;
|
|
|
|
if (data.readInt32()) {
|
2014-03-21 01:46:24 +00:00
|
|
|
stream = NativeHandle::create(data.readNativeHandle(), true);
|
2014-03-03 23:42:54 +00:00
|
|
|
}
|
|
|
|
status_t result = setSidebandStream(stream);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
2014-11-18 18:24:03 +00:00
|
|
|
}
|
2015-04-17 00:28:43 +00:00
|
|
|
case ALLOCATE_BUFFERS: {
|
2014-06-20 20:13:57 +00:00
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
|
|
|
bool async = static_cast<bool>(data.readInt32());
|
2014-11-18 18:24:03 +00:00
|
|
|
uint32_t width = data.readUint32();
|
|
|
|
uint32_t height = data.readUint32();
|
|
|
|
PixelFormat format = static_cast<PixelFormat>(data.readInt32());
|
|
|
|
uint32_t usage = data.readUint32();
|
2014-06-20 20:13:57 +00:00
|
|
|
allocateBuffers(async, width, height, format, usage);
|
|
|
|
return NO_ERROR;
|
2015-04-17 00:28:43 +00:00
|
|
|
}
|
|
|
|
case ALLOW_ALLOCATION: {
|
|
|
|
CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
|
|
|
|
bool allow = static_cast<bool>(data.readInt32());
|
|
|
|
status_t result = allowAllocation(allow);
|
|
|
|
reply->writeInt32(result);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
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)
|
2015-02-20 00:10:43 +00:00
|
|
|
+ sizeof(dataSpace)
|
2012-06-28 19:52:05 +00:00
|
|
|
+ sizeof(crop)
|
|
|
|
+ sizeof(scalingMode)
|
|
|
|
+ sizeof(transform)
|
2014-06-27 22:51:55 +00:00
|
|
|
+ sizeof(stickyTransform)
|
2013-07-19 05:10:56 +00:00
|
|
|
+ sizeof(async)
|
2015-03-17 23:23:42 +00:00
|
|
|
+ fence->getFlattenedSize()
|
|
|
|
+ surfaceDamage.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);
|
2015-02-20 00:10:43 +00:00
|
|
|
FlattenableUtils::write(buffer, size, dataSpace);
|
2013-07-30 04:24:40 +00:00
|
|
|
FlattenableUtils::write(buffer, size, crop);
|
|
|
|
FlattenableUtils::write(buffer, size, scalingMode);
|
|
|
|
FlattenableUtils::write(buffer, size, transform);
|
2014-06-27 22:51:55 +00:00
|
|
|
FlattenableUtils::write(buffer, size, stickyTransform);
|
2013-07-30 04:24:40 +00:00
|
|
|
FlattenableUtils::write(buffer, size, async);
|
2015-03-17 23:23:42 +00:00
|
|
|
status_t result = fence->flatten(buffer, size, fds, count);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return surfaceDamage.flatten(buffer, size);
|
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)
|
2015-02-20 00:10:43 +00:00
|
|
|
+ sizeof(dataSpace)
|
2013-07-30 04:24:40 +00:00
|
|
|
+ sizeof(crop)
|
|
|
|
+ sizeof(scalingMode)
|
|
|
|
+ sizeof(transform)
|
2014-06-27 22:51:55 +00:00
|
|
|
+ sizeof(stickyTransform)
|
2013-07-30 04:24:40 +00:00
|
|
|
+ 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);
|
2015-02-20 00:10:43 +00:00
|
|
|
FlattenableUtils::read(buffer, size, dataSpace);
|
2013-07-30 04:24:40 +00:00
|
|
|
FlattenableUtils::read(buffer, size, crop);
|
|
|
|
FlattenableUtils::read(buffer, size, scalingMode);
|
|
|
|
FlattenableUtils::read(buffer, size, transform);
|
2014-06-27 22:51:55 +00:00
|
|
|
FlattenableUtils::read(buffer, size, stickyTransform);
|
2013-07-30 04:24:40 +00:00
|
|
|
FlattenableUtils::read(buffer, size, async);
|
|
|
|
|
2012-12-20 22:05:45 +00:00
|
|
|
fence = new Fence();
|
2015-03-17 23:23:42 +00:00
|
|
|
status_t result = fence->unflatten(buffer, size, fds, count);
|
|
|
|
if (result != NO_ERROR) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return surfaceDamage.unflatten(buffer, size);
|
2012-06-28 19:52:05 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
}; // namespace android
|