use in/out structures for queueBuffer() IPC

Change-Id: Ie125df2444b62a9a2200586a717dca268852afc9
This commit is contained in:
Mathias Agopian 2012-04-09 16:14:01 -07:00
parent cac72cdbdf
commit f0bc2f1d8d
5 changed files with 76 additions and 39 deletions

View File

@ -125,9 +125,9 @@ public:
// nanoseconds, and must be monotonically increasing. Its other semantics
// (zero point, etc) are client-dependent and should be documented by the
// client.
virtual status_t queueBuffer(int buf, int64_t timestamp,
const Rect& crop, int scalingMode, uint32_t transform,
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
virtual status_t queueBuffer(int buf,
const QueueBufferInput& input, QueueBufferOutput* output);
virtual void cancelBuffer(int buf);
// setSynchronousMode set whether dequeueBuffer is synchronous or

View File

@ -82,9 +82,50 @@ protected:
// outWidth, outHeight and outTransform are filled with the default width
// and height of the window and current transform applied to buffers,
// respectively.
virtual status_t queueBuffer(int slot, int64_t timestamp,
const Rect& crop, int scalingMode, uint32_t transform,
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) = 0;
// QueueBufferInput must be a POD structure
struct QueueBufferInput {
inline QueueBufferInput(int64_t timestamp,
const Rect& crop, int scalingMode, uint32_t transform)
: timestamp(timestamp), crop(crop), scalingMode(scalingMode),
transform(transform) { }
inline void deflate(int64_t* outTimestamp, Rect* outCrop,
int* outScalingMode, uint32_t* outTransform) const {
*outTimestamp = timestamp;
*outCrop = crop;
*outScalingMode = scalingMode;
*outTransform = transform;
}
private:
int64_t timestamp;
Rect crop;
int scalingMode;
uint32_t transform;
};
// QueueBufferOutput must be a POD structure
struct QueueBufferOutput {
inline QueueBufferOutput() { }
inline void deflate(uint32_t* outWidth,
uint32_t* outHeight, uint32_t* outTransformHint) const {
*outWidth = width;
*outHeight = height;
*outTransformHint = transformHint;
}
inline void inflate(uint32_t inWidth, uint32_t inHeight,
uint32_t inTransformHint) {
width = inWidth;
height = inHeight;
transformHint = inTransformHint;
}
private:
uint32_t width;
uint32_t height;
uint32_t transformHint;
};
virtual status_t queueBuffer(int slot,
const QueueBufferInput& input, QueueBufferOutput* output) = 0;
// cancelBuffer indicates that the client does not wish to fill in the
// buffer associated with slot and transfers ownership of the slot back to

View File

@ -526,9 +526,8 @@ status_t BufferQueue::setSynchronousMode(bool enabled) {
return err;
}
status_t BufferQueue::queueBuffer(int buf, int64_t timestamp,
const Rect& crop, int scalingMode, uint32_t transform,
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
status_t BufferQueue::queueBuffer(int buf,
const QueueBufferInput& input, QueueBufferOutput* output) {
ATRACE_CALL();
ATRACE_BUFFER_INDEX(buf);
@ -581,6 +580,15 @@ status_t BufferQueue::queueBuffer(int buf, int64_t timestamp,
}
}
int scalingMode;
input.deflate(
&mSlots[buf].mTimestamp,
&mSlots[buf].mCrop,
&scalingMode,
&mSlots[buf].mTransform);
switch (scalingMode) {
case NATIVE_WINDOW_SCALING_MODE_FREEZE:
case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
@ -592,19 +600,14 @@ status_t BufferQueue::queueBuffer(int buf, int64_t timestamp,
}
mSlots[buf].mBufferState = BufferSlot::QUEUED;
mSlots[buf].mCrop = crop;
mSlots[buf].mTransform = transform;
mSlots[buf].mScalingMode = scalingMode;
mSlots[buf].mTimestamp = timestamp;
mFrameCounter++;
mSlots[buf].mFrameNumber = mFrameCounter;
mBufferHasBeenQueued = true;
mDequeueCondition.broadcast();
*outWidth = mDefaultWidth;
*outHeight = mDefaultHeight;
*outTransform = mTransformHint;
output->inflate(mDefaultWidth, mDefaultHeight, mDefaultHeight);
ATRACE_INT(mConsumerName.string(), mQueue.size());
} // scope for the lock

View File

@ -98,23 +98,17 @@ public:
return result;
}
virtual status_t queueBuffer(int buf, int64_t timestamp,
const Rect& crop, int scalingMode, uint32_t transform,
uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
virtual status_t queueBuffer(int buf,
const QueueBufferInput& input, QueueBufferOutput* output) {
Parcel data, reply;
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
data.writeInt32(buf);
data.writeInt64(timestamp);
memcpy(data.writeInplace(sizeof(Rect)), &crop, sizeof(Rect));
data.writeInt32(scalingMode);
data.writeInt32(transform);
memcpy(data.writeInplace(sizeof(input)), &input, sizeof(input));
status_t result = remote()->transact(QUEUE_BUFFER, data, &reply);
if (result != NO_ERROR) {
return result;
}
*outWidth = reply.readInt32();
*outHeight = reply.readInt32();
*outTransform = reply.readInt32();
memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output));
result = reply.readInt32();
return result;
}
@ -222,17 +216,13 @@ status_t BnSurfaceTexture::onTransact(
case QUEUE_BUFFER: {
CHECK_INTERFACE(ISurfaceTexture, data, reply);
int buf = data.readInt32();
int64_t timestamp = data.readInt64();
Rect crop( *reinterpret_cast<Rect const *>(data.readInplace(sizeof(Rect))) );
int scalingMode = data.readInt32();
uint32_t transform = data.readInt32();
uint32_t outWidth, outHeight, outTransform;
status_t result = queueBuffer(buf, timestamp,
crop, scalingMode, transform,
&outWidth, &outHeight, &outTransform);
reply->writeInt32(outWidth);
reply->writeInt32(outHeight);
reply->writeInt32(outTransform);
QueueBufferInput const* const input =
reinterpret_cast<QueueBufferInput const *>(
data.readInplace(sizeof(QueueBufferInput)));
QueueBufferOutput* const output =
reinterpret_cast<QueueBufferOutput *>(
reply->writeInplace(sizeof(QueueBufferOutput)));
status_t result = queueBuffer(buf, *input, output);
reply->writeInt32(result);
return NO_ERROR;
} break;

View File

@ -230,12 +230,15 @@ int SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer) {
if (i < 0) {
return i;
}
status_t err = mSurfaceTexture->queueBuffer(i, timestamp,
mCrop, mScalingMode, mTransform,
&mDefaultWidth, &mDefaultHeight, &mTransformHint);
ISurfaceTexture::QueueBufferOutput output;
ISurfaceTexture::QueueBufferInput input(timestamp,
mCrop, mScalingMode, mTransform);
status_t err = mSurfaceTexture->queueBuffer(i, input, &output);
if (err != OK) {
ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err);
}
output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint);
return err;
}