widget/gonk/nativewindow/IGonkGraphicBufferConsumer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/nativewindow/IGonkGraphicBufferConsumer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,227 @@
     1.4 +/*
     1.5 + * Copyright (C) 2013 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef ANDROID_GUI_IGONKGRAPHICBUFFERCONSUMER_H
    1.21 +#define ANDROID_GUI_IGONKGRAPHICBUFFERCONSUMER_H
    1.22 +
    1.23 +#include <stdint.h>
    1.24 +#include <sys/types.h>
    1.25 +
    1.26 +#include <utils/Errors.h>
    1.27 +#include <utils/RefBase.h>
    1.28 +#include <utils/Timers.h>
    1.29 +
    1.30 +#include <binder/IInterface.h>
    1.31 +#include <ui/Rect.h>
    1.32 +
    1.33 +#include "mozilla/layers/LayersSurfaces.h"
    1.34 +
    1.35 +namespace mozilla {
    1.36 +
    1.37 +namespace layers {
    1.38 +class TextureClient;
    1.39 +}
    1.40 +}
    1.41 +
    1.42 +namespace android {
    1.43 +// ----------------------------------------------------------------------------
    1.44 +
    1.45 +class IConsumerListener;
    1.46 +class GraphicBuffer;
    1.47 +class Fence;
    1.48 +
    1.49 +class IGonkGraphicBufferConsumer : public IInterface {
    1.50 +    typedef mozilla::layers::TextureClient TextureClient;
    1.51 +public:
    1.52 +
    1.53 +    // public facing structure for BufferSlot
    1.54 +    class BufferItem : public Flattenable<BufferItem> {
    1.55 +        friend class Flattenable<BufferItem>;
    1.56 +        size_t getPodSize() const;
    1.57 +        size_t getFlattenedSize() const;
    1.58 +        size_t getFdCount() const;
    1.59 +        status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
    1.60 +        status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
    1.61 +
    1.62 +    public:
    1.63 +        enum { INVALID_BUFFER_SLOT = -1 };
    1.64 +        BufferItem();
    1.65 +
    1.66 +        // mGraphicBuffer points to the buffer allocated for this slot, or is NULL
    1.67 +        // if the buffer in this slot has been acquired in the past (see
    1.68 +        // BufferSlot.mAcquireCalled).
    1.69 +        sp<GraphicBuffer> mGraphicBuffer;
    1.70 +
    1.71 +        // mFence is a fence that will signal when the buffer is idle.
    1.72 +        sp<Fence> mFence;
    1.73 +
    1.74 +        // mCrop is the current crop rectangle for this buffer slot.
    1.75 +        Rect mCrop;
    1.76 +
    1.77 +        // mTransform is the current transform flags for this buffer slot.
    1.78 +        uint32_t mTransform;
    1.79 +
    1.80 +        // mScalingMode is the current scaling mode for this buffer slot.
    1.81 +        uint32_t mScalingMode;
    1.82 +
    1.83 +        // mTimestamp is the current timestamp for this buffer slot. This gets
    1.84 +        // to set by queueBuffer each time this slot is queued.
    1.85 +        int64_t mTimestamp;
    1.86 +
    1.87 +        // mIsAutoTimestamp indicates whether mTimestamp was generated
    1.88 +        // automatically when the buffer was queued.
    1.89 +        bool mIsAutoTimestamp;
    1.90 +
    1.91 +        // mFrameNumber is the number of the queued frame for this slot.
    1.92 +        uint64_t mFrameNumber;
    1.93 +
    1.94 +        // mBuf is the slot index of this buffer
    1.95 +        int mBuf;
    1.96 +
    1.97 +        // mIsDroppable whether this buffer was queued with the
    1.98 +        // property that it can be replaced by a new buffer for the purpose of
    1.99 +        // making sure dequeueBuffer() won't block.
   1.100 +        // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer
   1.101 +        // was queued.
   1.102 +        bool mIsDroppable;
   1.103 +
   1.104 +        // Indicates whether this buffer has been seen by a consumer yet
   1.105 +        bool mAcquireCalled;
   1.106 +
   1.107 +        // Indicates this buffer must be transformed by the inverse transform of the screen
   1.108 +        // it is displayed onto. This is applied after mTransform.
   1.109 +        bool mTransformToDisplayInverse;
   1.110 +    };
   1.111 +
   1.112 +
   1.113 +    // acquireBuffer attempts to acquire ownership of the next pending buffer in
   1.114 +    // the BufferQueue.  If no buffer is pending then it returns -EINVAL.  If a
   1.115 +    // buffer is successfully acquired, the information about the buffer is
   1.116 +    // returned in BufferItem.  If the buffer returned had previously been
   1.117 +    // acquired then the BufferItem::mGraphicBuffer field of buffer is set to
   1.118 +    // NULL and it is assumed that the consumer still holds a reference to the
   1.119 +    // buffer.
   1.120 +    //
   1.121 +    // If presentWhen is nonzero, it indicates the time when the buffer will
   1.122 +    // be displayed on screen.  If the buffer's timestamp is farther in the
   1.123 +    // future, the buffer won't be acquired, and PRESENT_LATER will be
   1.124 +    // returned.  The presentation time is in nanoseconds, and the time base
   1.125 +    // is CLOCK_MONOTONIC.
   1.126 +    virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen) = 0;
   1.127 +
   1.128 +    // releaseBuffer releases a buffer slot from the consumer back to the
   1.129 +    // BufferQueue.  This may be done while the buffer's contents are still
   1.130 +    // being accessed.  The fence will signal when the buffer is no longer
   1.131 +    // in use. frameNumber is used to indentify the exact buffer returned.
   1.132 +    //
   1.133 +    // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
   1.134 +    // any references to the just-released buffer that it might have, as if it
   1.135 +    // had received a onBuffersReleased() call with a mask set for the released
   1.136 +    // buffer.
   1.137 +    //
   1.138 +    // Note that the dependencies on EGL will be removed once we switch to using
   1.139 +    // the Android HW Sync HAL.
   1.140 +    virtual status_t releaseBuffer(int buf, uint64_t frameNumber, const sp<Fence>& releaseFence) = 0;
   1.141 +
   1.142 +    // consumerConnect connects a consumer to the BufferQueue.  Only one
   1.143 +    // consumer may be connected, and when that consumer disconnects the
   1.144 +    // BufferQueue is placed into the "abandoned" state, causing most
   1.145 +    // interactions with the BufferQueue by the producer to fail.
   1.146 +    // controlledByApp indicates whether the consumer is controlled by
   1.147 +    // the application.
   1.148 +    //
   1.149 +    // consumer may not be NULL.
   1.150 +    virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) = 0;
   1.151 +
   1.152 +    // consumerDisconnect disconnects a consumer from the BufferQueue. All
   1.153 +    // buffers will be freed and the BufferQueue is placed in the "abandoned"
   1.154 +    // state, causing most interactions with the BufferQueue by the producer to
   1.155 +    // fail.
   1.156 +    virtual status_t consumerDisconnect() = 0;
   1.157 +
   1.158 +    // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
   1.159 +    // indicating which buffer slots have been released by the BufferQueue
   1.160 +    // but have not yet been released by the consumer.
   1.161 +    //
   1.162 +    // This should be called from the onBuffersReleased() callback.
   1.163 +    virtual status_t getReleasedBuffers(uint32_t* slotMask) = 0;
   1.164 +
   1.165 +    // setDefaultBufferSize is used to set the size of buffers returned by
   1.166 +    // dequeueBuffer when a width and height of zero is requested.  Default
   1.167 +    // is 1x1.
   1.168 +    virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) = 0;
   1.169 +
   1.170 +    // setDefaultMaxBufferCount sets the default value for the maximum buffer
   1.171 +    // count (the initial default is 2). If the producer has requested a
   1.172 +    // buffer count using setBufferCount, the default buffer count will only
   1.173 +    // take effect if the producer sets the count back to zero.
   1.174 +    //
   1.175 +    // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
   1.176 +    virtual status_t setDefaultMaxBufferCount(int bufferCount) = 0;
   1.177 +
   1.178 +    // disableAsyncBuffer disables the extra buffer used in async mode
   1.179 +    // (when both producer and consumer have set their "isControlledByApp"
   1.180 +    // flag) and has dequeueBuffer() return WOULD_BLOCK instead.
   1.181 +    //
   1.182 +    // This can only be called before consumerConnect().
   1.183 +    virtual status_t disableAsyncBuffer() = 0;
   1.184 +
   1.185 +    // setMaxAcquiredBufferCount sets the maximum number of buffers that can
   1.186 +    // be acquired by the consumer at one time (default 1).  This call will
   1.187 +    // fail if a producer is connected to the BufferQueue.
   1.188 +    virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0;
   1.189 +
   1.190 +    // setConsumerName sets the name used in logging
   1.191 +    virtual void setConsumerName(const String8& name) = 0;
   1.192 +
   1.193 +    // setDefaultBufferFormat allows the BufferQueue to create
   1.194 +    // GraphicBuffers of a defaultFormat if no format is specified
   1.195 +    // in dequeueBuffer.  Formats are enumerated in graphics.h; the
   1.196 +    // initial default is HAL_PIXEL_FORMAT_RGBA_8888.
   1.197 +    virtual status_t setDefaultBufferFormat(uint32_t defaultFormat) = 0;
   1.198 +
   1.199 +    // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer.
   1.200 +    // These are merged with the bits passed to dequeueBuffer.  The values are
   1.201 +    // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
   1.202 +    virtual status_t setConsumerUsageBits(uint32_t usage) = 0;
   1.203 +
   1.204 +    // setTransformHint bakes in rotation to buffers so overlays can be used.
   1.205 +    // The values are enumerated in window.h, e.g.
   1.206 +    // NATIVE_WINDOW_TRANSFORM_ROT_90.  The default is 0 (no transform).
   1.207 +    virtual status_t setTransformHint(uint32_t hint) = 0;
   1.208 +
   1.209 +    // dump state into a string
   1.210 +    virtual void dump(String8& result, const char* prefix) const = 0;
   1.211 +
   1.212 +public:
   1.213 +    DECLARE_META_INTERFACE(GonkGraphicBufferConsumer);
   1.214 +};
   1.215 +
   1.216 +// ----------------------------------------------------------------------------
   1.217 +
   1.218 +class BnGonkGraphicBufferConsumer : public BnInterface<IGonkGraphicBufferConsumer>
   1.219 +{
   1.220 +public:
   1.221 +    virtual status_t    onTransact( uint32_t code,
   1.222 +                                    const Parcel& data,
   1.223 +                                    Parcel* reply,
   1.224 +                                    uint32_t flags = 0);
   1.225 +};
   1.226 +
   1.227 +// ----------------------------------------------------------------------------
   1.228 +}; // namespace android
   1.229 +
   1.230 +#endif // ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H

mercurial