libgui: Add dequeue/attach timeout
Adds the ability to specify the timeout when dequeueBuffer or
attachBuffer block due to the lack of a free buffer/slot. By default,
these will block indefinitely (which is signified by a timeout of -1).
When a timeout (other than -1) is specified, non-blocking mode is
disabled and the given timeout will be used instead.
Bug: 25196773
Change-Id: I17fdbeebccb7c8d878703d758ac1209608258e61
diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp
index d5310bd..0cca58d 100644
--- a/libs/gui/IGraphicBufferProducer.cpp
+++ b/libs/gui/IGraphicBufferProducer.cpp
@@ -51,7 +51,8 @@
SET_MAX_DEQUEUED_BUFFER_COUNT,
SET_ASYNC_MODE,
GET_NEXT_FRAME_NUMBER,
- SET_SINGLE_BUFFER_MODE
+ SET_SINGLE_BUFFER_MODE,
+ SET_DEQUEUE_TIMEOUT,
};
class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
@@ -353,6 +354,18 @@
}
return result;
}
+
+ virtual status_t setDequeueTimeout(nsecs_t timeout) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
+ data.writeInt64(timeout);
+ status_t result = remote()->transact(SET_DEQUEUE_TIMEOUT, data, &reply);
+ if (result != NO_ERROR) {
+ ALOGE("setDequeueTimeout failed to transact: %d", result);
+ return result;
+ }
+ return reply.readInt32();
+ }
};
// Out-of-line virtual method definition to trigger vtable emission in this
@@ -548,6 +561,13 @@
reply->writeInt32(result);
return NO_ERROR;
}
+ case SET_DEQUEUE_TIMEOUT: {
+ CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
+ nsecs_t timeout = data.readInt64();
+ status_t result = setDequeueTimeout(timeout);
+ reply->writeInt32(result);
+ return NO_ERROR;
+ }
}
return BBinder::onTransact(code, data, reply, flags);
}