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.
|
|
|
|
*/
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
#ifndef ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|
|
|
|
#define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/RefBase.h>
|
|
|
|
|
|
|
|
#include <binder/IInterface.h>
|
|
|
|
|
2012-06-14 22:26:33 +00:00
|
|
|
#include <ui/Fence.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
#include <ui/Rect.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2013-02-15 01:11:02 +00:00
|
|
|
class Surface;
|
2011-04-20 21:20:59 +00:00
|
|
|
|
2012-12-13 01:10:08 +00:00
|
|
|
/*
|
2013-01-08 19:25:51 +00:00
|
|
|
* This class defines the Binder IPC interface for the producer side of
|
|
|
|
* a queue of graphics buffers. It's used to send graphics data from one
|
|
|
|
* component to another. For example, a class that decodes video for
|
|
|
|
* playback might use this to provide frames. This is typically done
|
2013-02-15 01:11:02 +00:00
|
|
|
* indirectly, through Surface.
|
2012-12-13 01:10:08 +00:00
|
|
|
*
|
2013-01-08 19:25:51 +00:00
|
|
|
* The underlying mechanism is a BufferQueue, which implements
|
|
|
|
* BnGraphicBufferProducer. In normal operation, the producer calls
|
|
|
|
* dequeueBuffer() to get an empty buffer, fills it with data, then
|
|
|
|
* calls queueBuffer() to make it available to the consumer.
|
2012-12-13 01:10:08 +00:00
|
|
|
*
|
2012-12-18 17:49:45 +00:00
|
|
|
* This class was previously called ISurfaceTexture.
|
2012-12-13 01:10:08 +00:00
|
|
|
*/
|
2012-12-18 17:49:45 +00:00
|
|
|
class IGraphicBufferProducer : public IInterface
|
2010-12-20 19:27:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-12-18 17:49:45 +00:00
|
|
|
DECLARE_META_INTERFACE(GraphicBufferProducer);
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-05-03 02:51:12 +00:00
|
|
|
enum {
|
|
|
|
BUFFER_NEEDS_REALLOCATION = 0x1,
|
|
|
|
RELEASE_ALL_BUFFERS = 0x2,
|
|
|
|
};
|
2011-04-01 02:10:24 +00:00
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
// requestBuffer requests a new buffer for the given index. The server (i.e.
|
2012-12-18 17:49:45 +00:00
|
|
|
// the IGraphicBufferProducer implementation) assigns the newly created
|
|
|
|
// buffer to the given slot index, and the client is expected to mirror the
|
2010-12-20 19:27:26 +00:00
|
|
|
// slot->buffer mapping so that it's not necessary to transfer a
|
|
|
|
// GraphicBuffer for every dequeue operation.
|
2011-07-19 19:08:33 +00:00
|
|
|
virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// setBufferCount sets the number of buffer slots available. Calling this
|
|
|
|
// will also cause all buffer slots to be emptied. The caller should empty
|
|
|
|
// its mirrored copy of the buffer slots when calling this method.
|
|
|
|
virtual status_t setBufferCount(int bufferCount) = 0;
|
|
|
|
|
|
|
|
// dequeueBuffer requests a new buffer slot for the client to use. Ownership
|
|
|
|
// of the slot is transfered to the client, meaning that the server will not
|
|
|
|
// use the contents of the buffer associated with that slot. The slot index
|
|
|
|
// returned may or may not contain a buffer. If the slot is empty the client
|
|
|
|
// should call requestBuffer to assign a new buffer to that slot. The client
|
|
|
|
// is expected to either call cancelBuffer on the dequeued slot or to fill
|
|
|
|
// in the contents of its associated buffer contents and call queueBuffer.
|
2011-04-01 02:10:24 +00:00
|
|
|
// If dequeueBuffer return BUFFER_NEEDS_REALLOCATION, the client is
|
|
|
|
// expected to call requestBuffer immediately.
|
2012-06-14 22:26:33 +00:00
|
|
|
//
|
|
|
|
// The fence parameter will be updated to hold the fence associated with
|
|
|
|
// the buffer. The contents of the buffer must not be overwritten until the
|
|
|
|
// fence signals. If the fence is NULL, the buffer may be written
|
|
|
|
// immediately.
|
2013-07-19 05:10:56 +00:00
|
|
|
//
|
|
|
|
// The async parameter sets whether we're in asynchrnous mode for this
|
|
|
|
// deququeBuffer() call.
|
|
|
|
virtual status_t dequeueBuffer(int *slot, 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) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// queueBuffer indicates that the client has finished filling in the
|
|
|
|
// contents of the buffer associated with slot and transfers ownership of
|
|
|
|
// that slot back to the server. It is not valid to call queueBuffer on a
|
|
|
|
// slot that is not owned by the client or one for which a buffer associated
|
2011-02-18 19:02:42 +00:00
|
|
|
// via requestBuffer. In addition, a timestamp must be provided by the
|
|
|
|
// client for this buffer. The timestamp is measured in nanoseconds, and
|
|
|
|
// must be monotonically increasing. Its other properties (zero point, etc)
|
|
|
|
// are client-dependent, and should be documented by the client.
|
2011-07-19 22:24:46 +00:00
|
|
|
//
|
2013-07-19 05:10:56 +00:00
|
|
|
// The async parameter sets whether we're queuing a buffer in asynchronous mode.
|
|
|
|
//
|
2011-07-20 23:46:11 +00:00
|
|
|
// outWidth, outHeight and outTransform are filled with the default width
|
|
|
|
// and height of the window and current transform applied to buffers,
|
2011-07-19 22:24:46 +00:00
|
|
|
// respectively.
|
2012-04-09 23:14:01 +00:00
|
|
|
|
2013-07-30 04:24:40 +00:00
|
|
|
struct QueueBufferInput : public Flattenable<QueueBufferInput> {
|
|
|
|
friend class Flattenable<QueueBufferInput>;
|
2012-06-28 19:52:05 +00:00
|
|
|
inline QueueBufferInput(const Parcel& parcel);
|
2012-04-09 23:14:01 +00:00
|
|
|
inline QueueBufferInput(int64_t timestamp,
|
2013-07-19 05:10:56 +00:00
|
|
|
const Rect& crop, int scalingMode, uint32_t transform, bool async,
|
|
|
|
const sp<Fence>& fence)
|
2012-04-09 23:14:01 +00:00
|
|
|
: timestamp(timestamp), crop(crop), scalingMode(scalingMode),
|
2013-07-19 05:10:56 +00:00
|
|
|
transform(transform), async(async), fence(fence) { }
|
2012-04-09 23:14:01 +00:00
|
|
|
inline void deflate(int64_t* outTimestamp, Rect* outCrop,
|
2013-07-19 05:10:56 +00:00
|
|
|
int* outScalingMode, uint32_t* outTransform, bool* outAsync,
|
2012-06-28 19:52:05 +00:00
|
|
|
sp<Fence>* outFence) const {
|
2012-04-09 23:14:01 +00:00
|
|
|
*outTimestamp = timestamp;
|
|
|
|
*outCrop = crop;
|
|
|
|
*outScalingMode = scalingMode;
|
|
|
|
*outTransform = transform;
|
2013-07-19 05:10:56 +00:00
|
|
|
*outAsync = bool(async);
|
2012-06-28 19:52:05 +00:00
|
|
|
*outFence = fence;
|
2012-04-09 23:14:01 +00:00
|
|
|
}
|
2012-06-28 19:52:05 +00:00
|
|
|
|
2013-07-30 04:24:40 +00:00
|
|
|
// Flattenable protocol
|
|
|
|
size_t getFlattenedSize() const;
|
|
|
|
size_t getFdCount() const;
|
|
|
|
status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
|
|
|
|
status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
|
2012-06-28 19:52:05 +00:00
|
|
|
|
2012-04-09 23:14:01 +00:00
|
|
|
private:
|
|
|
|
int64_t timestamp;
|
|
|
|
Rect crop;
|
|
|
|
int scalingMode;
|
|
|
|
uint32_t transform;
|
2013-07-19 05:10:56 +00:00
|
|
|
int async;
|
2012-06-28 19:52:05 +00:00
|
|
|
sp<Fence> fence;
|
2012-04-09 23:14:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// QueueBufferOutput must be a POD structure
|
|
|
|
struct QueueBufferOutput {
|
|
|
|
inline QueueBufferOutput() { }
|
|
|
|
inline void deflate(uint32_t* outWidth,
|
2012-04-21 00:19:28 +00:00
|
|
|
uint32_t* outHeight,
|
|
|
|
uint32_t* outTransformHint,
|
|
|
|
uint32_t* outNumPendingBuffers) const {
|
2012-04-09 23:14:01 +00:00
|
|
|
*outWidth = width;
|
|
|
|
*outHeight = height;
|
|
|
|
*outTransformHint = transformHint;
|
2012-04-21 00:19:28 +00:00
|
|
|
*outNumPendingBuffers = numPendingBuffers;
|
2012-04-09 23:14:01 +00:00
|
|
|
}
|
|
|
|
inline void inflate(uint32_t inWidth, uint32_t inHeight,
|
2012-04-21 00:19:28 +00:00
|
|
|
uint32_t inTransformHint, uint32_t inNumPendingBuffers) {
|
2012-04-09 23:14:01 +00:00
|
|
|
width = inWidth;
|
|
|
|
height = inHeight;
|
|
|
|
transformHint = inTransformHint;
|
2012-04-21 00:19:28 +00:00
|
|
|
numPendingBuffers = inNumPendingBuffers;
|
2012-04-09 23:14:01 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint32_t transformHint;
|
2012-04-21 00:19:28 +00:00
|
|
|
uint32_t numPendingBuffers;
|
2012-04-09 23:14:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual status_t queueBuffer(int slot,
|
|
|
|
const QueueBufferInput& input, QueueBufferOutput* output) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
|
|
|
// cancelBuffer indicates that the client does not wish to fill in the
|
|
|
|
// buffer associated with slot and transfers ownership of the slot back to
|
|
|
|
// the server.
|
2013-03-16 04:34:30 +00:00
|
|
|
virtual void cancelBuffer(int slot, const sp<Fence>& fence) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
// query retrieves some information for this surface
|
|
|
|
// 'what' tokens allowed are that of android_natives.h
|
|
|
|
virtual int query(int what, int* value) = 0;
|
2011-05-03 02:51:12 +00:00
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
// connect attempts to connect a client API to the IGraphicBufferProducer.
|
|
|
|
// This must be called before any other IGraphicBufferProducer methods are
|
|
|
|
// called except for getAllocator.
|
2011-07-14 02:12:20 +00:00
|
|
|
//
|
|
|
|
// This method will fail if the connect was previously called on the
|
2012-12-18 17:49:45 +00:00
|
|
|
// IGraphicBufferProducer and no corresponding disconnect call was made.
|
2011-08-09 02:14:03 +00:00
|
|
|
//
|
|
|
|
// outWidth, outHeight and outTransform are filled with the default width
|
|
|
|
// and height of the window and current transform applied to buffers,
|
|
|
|
// respectively.
|
2013-07-17 05:56:09 +00:00
|
|
|
virtual status_t connect(int api, bool producerControlledByApp, QueueBufferOutput* output) = 0;
|
2011-07-14 02:12:20 +00:00
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
// disconnect attempts to disconnect a client API from the
|
|
|
|
// IGraphicBufferProducer. Calling this method will cause any subsequent
|
|
|
|
// calls to other IGraphicBufferProducer methods to fail except for
|
|
|
|
// getAllocator and connect. Successfully calling connect after this will
|
|
|
|
// allow the other methods to succeed again.
|
2011-07-14 02:12:20 +00:00
|
|
|
//
|
2012-12-18 17:49:45 +00:00
|
|
|
// This method will fail if the the IGraphicBufferProducer is not currently
|
2011-07-14 02:12:20 +00:00
|
|
|
// connected to the specified client API.
|
|
|
|
virtual status_t disconnect(int api) = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer>
|
2010-12-20 19:27:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual status_t onTransact( uint32_t code,
|
|
|
|
const Parcel& data,
|
|
|
|
Parcel* reply,
|
|
|
|
uint32_t flags = 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|
2012-12-18 17:49:45 +00:00
|
|
|
#endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|