michael@0: /* michael@0: * Copyright (C) 2013 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef ANDROID_GUI_IGONKGRAPHICBUFFERCONSUMER_H michael@0: #define ANDROID_GUI_IGONKGRAPHICBUFFERCONSUMER_H michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "mozilla/layers/LayersSurfaces.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace layers { michael@0: class TextureClient; michael@0: } michael@0: } michael@0: michael@0: namespace android { michael@0: // ---------------------------------------------------------------------------- michael@0: michael@0: class IConsumerListener; michael@0: class GraphicBuffer; michael@0: class Fence; michael@0: michael@0: class IGonkGraphicBufferConsumer : public IInterface { michael@0: typedef mozilla::layers::TextureClient TextureClient; michael@0: public: michael@0: michael@0: // public facing structure for BufferSlot michael@0: class BufferItem : public Flattenable { michael@0: friend class Flattenable; michael@0: size_t getPodSize() const; michael@0: size_t getFlattenedSize() const; michael@0: size_t getFdCount() const; michael@0: status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; michael@0: status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); michael@0: michael@0: public: michael@0: enum { INVALID_BUFFER_SLOT = -1 }; michael@0: BufferItem(); michael@0: michael@0: // mGraphicBuffer points to the buffer allocated for this slot, or is NULL michael@0: // if the buffer in this slot has been acquired in the past (see michael@0: // BufferSlot.mAcquireCalled). michael@0: sp mGraphicBuffer; michael@0: michael@0: // mFence is a fence that will signal when the buffer is idle. michael@0: sp mFence; michael@0: michael@0: // mCrop is the current crop rectangle for this buffer slot. michael@0: Rect mCrop; michael@0: michael@0: // mTransform is the current transform flags for this buffer slot. michael@0: uint32_t mTransform; michael@0: michael@0: // mScalingMode is the current scaling mode for this buffer slot. michael@0: uint32_t mScalingMode; michael@0: michael@0: // mTimestamp is the current timestamp for this buffer slot. This gets michael@0: // to set by queueBuffer each time this slot is queued. michael@0: int64_t mTimestamp; michael@0: michael@0: // mIsAutoTimestamp indicates whether mTimestamp was generated michael@0: // automatically when the buffer was queued. michael@0: bool mIsAutoTimestamp; michael@0: michael@0: // mFrameNumber is the number of the queued frame for this slot. michael@0: uint64_t mFrameNumber; michael@0: michael@0: // mBuf is the slot index of this buffer michael@0: int mBuf; michael@0: michael@0: // mIsDroppable whether this buffer was queued with the michael@0: // property that it can be replaced by a new buffer for the purpose of michael@0: // making sure dequeueBuffer() won't block. michael@0: // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer michael@0: // was queued. michael@0: bool mIsDroppable; michael@0: michael@0: // Indicates whether this buffer has been seen by a consumer yet michael@0: bool mAcquireCalled; michael@0: michael@0: // Indicates this buffer must be transformed by the inverse transform of the screen michael@0: // it is displayed onto. This is applied after mTransform. michael@0: bool mTransformToDisplayInverse; michael@0: }; michael@0: michael@0: michael@0: // acquireBuffer attempts to acquire ownership of the next pending buffer in michael@0: // the BufferQueue. If no buffer is pending then it returns -EINVAL. If a michael@0: // buffer is successfully acquired, the information about the buffer is michael@0: // returned in BufferItem. If the buffer returned had previously been michael@0: // acquired then the BufferItem::mGraphicBuffer field of buffer is set to michael@0: // NULL and it is assumed that the consumer still holds a reference to the michael@0: // buffer. michael@0: // michael@0: // If presentWhen is nonzero, it indicates the time when the buffer will michael@0: // be displayed on screen. If the buffer's timestamp is farther in the michael@0: // future, the buffer won't be acquired, and PRESENT_LATER will be michael@0: // returned. The presentation time is in nanoseconds, and the time base michael@0: // is CLOCK_MONOTONIC. michael@0: virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen) = 0; michael@0: michael@0: // releaseBuffer releases a buffer slot from the consumer back to the michael@0: // BufferQueue. This may be done while the buffer's contents are still michael@0: // being accessed. The fence will signal when the buffer is no longer michael@0: // in use. frameNumber is used to indentify the exact buffer returned. michael@0: // michael@0: // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free michael@0: // any references to the just-released buffer that it might have, as if it michael@0: // had received a onBuffersReleased() call with a mask set for the released michael@0: // buffer. michael@0: // michael@0: // Note that the dependencies on EGL will be removed once we switch to using michael@0: // the Android HW Sync HAL. michael@0: virtual status_t releaseBuffer(int buf, uint64_t frameNumber, const sp& releaseFence) = 0; michael@0: michael@0: // consumerConnect connects a consumer to the BufferQueue. Only one michael@0: // consumer may be connected, and when that consumer disconnects the michael@0: // BufferQueue is placed into the "abandoned" state, causing most michael@0: // interactions with the BufferQueue by the producer to fail. michael@0: // controlledByApp indicates whether the consumer is controlled by michael@0: // the application. michael@0: // michael@0: // consumer may not be NULL. michael@0: virtual status_t consumerConnect(const sp& consumer, bool controlledByApp) = 0; michael@0: michael@0: // consumerDisconnect disconnects a consumer from the BufferQueue. All michael@0: // buffers will be freed and the BufferQueue is placed in the "abandoned" michael@0: // state, causing most interactions with the BufferQueue by the producer to michael@0: // fail. michael@0: virtual status_t consumerDisconnect() = 0; michael@0: michael@0: // getReleasedBuffers sets the value pointed to by slotMask to a bit mask michael@0: // indicating which buffer slots have been released by the BufferQueue michael@0: // but have not yet been released by the consumer. michael@0: // michael@0: // This should be called from the onBuffersReleased() callback. michael@0: virtual status_t getReleasedBuffers(uint32_t* slotMask) = 0; michael@0: michael@0: // setDefaultBufferSize is used to set the size of buffers returned by michael@0: // dequeueBuffer when a width and height of zero is requested. Default michael@0: // is 1x1. michael@0: virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) = 0; michael@0: michael@0: // setDefaultMaxBufferCount sets the default value for the maximum buffer michael@0: // count (the initial default is 2). If the producer has requested a michael@0: // buffer count using setBufferCount, the default buffer count will only michael@0: // take effect if the producer sets the count back to zero. michael@0: // michael@0: // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. michael@0: virtual status_t setDefaultMaxBufferCount(int bufferCount) = 0; michael@0: michael@0: // disableAsyncBuffer disables the extra buffer used in async mode michael@0: // (when both producer and consumer have set their "isControlledByApp" michael@0: // flag) and has dequeueBuffer() return WOULD_BLOCK instead. michael@0: // michael@0: // This can only be called before consumerConnect(). michael@0: virtual status_t disableAsyncBuffer() = 0; michael@0: michael@0: // setMaxAcquiredBufferCount sets the maximum number of buffers that can michael@0: // be acquired by the consumer at one time (default 1). This call will michael@0: // fail if a producer is connected to the BufferQueue. michael@0: virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0; michael@0: michael@0: // setConsumerName sets the name used in logging michael@0: virtual void setConsumerName(const String8& name) = 0; michael@0: michael@0: // setDefaultBufferFormat allows the BufferQueue to create michael@0: // GraphicBuffers of a defaultFormat if no format is specified michael@0: // in dequeueBuffer. Formats are enumerated in graphics.h; the michael@0: // initial default is HAL_PIXEL_FORMAT_RGBA_8888. michael@0: virtual status_t setDefaultBufferFormat(uint32_t defaultFormat) = 0; michael@0: michael@0: // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. michael@0: // These are merged with the bits passed to dequeueBuffer. The values are michael@0: // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. michael@0: virtual status_t setConsumerUsageBits(uint32_t usage) = 0; michael@0: michael@0: // setTransformHint bakes in rotation to buffers so overlays can be used. michael@0: // The values are enumerated in window.h, e.g. michael@0: // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). michael@0: virtual status_t setTransformHint(uint32_t hint) = 0; michael@0: michael@0: // dump state into a string michael@0: virtual void dump(String8& result, const char* prefix) const = 0; michael@0: michael@0: public: michael@0: DECLARE_META_INTERFACE(GonkGraphicBufferConsumer); michael@0: }; michael@0: michael@0: // ---------------------------------------------------------------------------- michael@0: michael@0: class BnGonkGraphicBufferConsumer : public BnInterface michael@0: { michael@0: public: michael@0: virtual status_t onTransact( uint32_t code, michael@0: const Parcel& data, michael@0: Parcel* reply, michael@0: uint32_t flags = 0); michael@0: }; michael@0: michael@0: // ---------------------------------------------------------------------------- michael@0: }; // namespace android michael@0: michael@0: #endif // ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H