widget/gonk/nativewindow/IGonkGraphicBufferConsumer.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /*
     2  * Copyright (C) 2013 The Android Open Source Project
     3  *
     4  * Licensed under the Apache License, Version 2.0 (the "License");
     5  * you may not use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  *      http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.
    15  */
    17 #ifndef ANDROID_GUI_IGONKGRAPHICBUFFERCONSUMER_H
    18 #define ANDROID_GUI_IGONKGRAPHICBUFFERCONSUMER_H
    20 #include <stdint.h>
    21 #include <sys/types.h>
    23 #include <utils/Errors.h>
    24 #include <utils/RefBase.h>
    25 #include <utils/Timers.h>
    27 #include <binder/IInterface.h>
    28 #include <ui/Rect.h>
    30 #include "mozilla/layers/LayersSurfaces.h"
    32 namespace mozilla {
    34 namespace layers {
    35 class TextureClient;
    36 }
    37 }
    39 namespace android {
    40 // ----------------------------------------------------------------------------
    42 class IConsumerListener;
    43 class GraphicBuffer;
    44 class Fence;
    46 class IGonkGraphicBufferConsumer : public IInterface {
    47     typedef mozilla::layers::TextureClient TextureClient;
    48 public:
    50     // public facing structure for BufferSlot
    51     class BufferItem : public Flattenable<BufferItem> {
    52         friend class Flattenable<BufferItem>;
    53         size_t getPodSize() const;
    54         size_t getFlattenedSize() const;
    55         size_t getFdCount() const;
    56         status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
    57         status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
    59     public:
    60         enum { INVALID_BUFFER_SLOT = -1 };
    61         BufferItem();
    63         // mGraphicBuffer points to the buffer allocated for this slot, or is NULL
    64         // if the buffer in this slot has been acquired in the past (see
    65         // BufferSlot.mAcquireCalled).
    66         sp<GraphicBuffer> mGraphicBuffer;
    68         // mFence is a fence that will signal when the buffer is idle.
    69         sp<Fence> mFence;
    71         // mCrop is the current crop rectangle for this buffer slot.
    72         Rect mCrop;
    74         // mTransform is the current transform flags for this buffer slot.
    75         uint32_t mTransform;
    77         // mScalingMode is the current scaling mode for this buffer slot.
    78         uint32_t mScalingMode;
    80         // mTimestamp is the current timestamp for this buffer slot. This gets
    81         // to set by queueBuffer each time this slot is queued.
    82         int64_t mTimestamp;
    84         // mIsAutoTimestamp indicates whether mTimestamp was generated
    85         // automatically when the buffer was queued.
    86         bool mIsAutoTimestamp;
    88         // mFrameNumber is the number of the queued frame for this slot.
    89         uint64_t mFrameNumber;
    91         // mBuf is the slot index of this buffer
    92         int mBuf;
    94         // mIsDroppable whether this buffer was queued with the
    95         // property that it can be replaced by a new buffer for the purpose of
    96         // making sure dequeueBuffer() won't block.
    97         // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer
    98         // was queued.
    99         bool mIsDroppable;
   101         // Indicates whether this buffer has been seen by a consumer yet
   102         bool mAcquireCalled;
   104         // Indicates this buffer must be transformed by the inverse transform of the screen
   105         // it is displayed onto. This is applied after mTransform.
   106         bool mTransformToDisplayInverse;
   107     };
   110     // acquireBuffer attempts to acquire ownership of the next pending buffer in
   111     // the BufferQueue.  If no buffer is pending then it returns -EINVAL.  If a
   112     // buffer is successfully acquired, the information about the buffer is
   113     // returned in BufferItem.  If the buffer returned had previously been
   114     // acquired then the BufferItem::mGraphicBuffer field of buffer is set to
   115     // NULL and it is assumed that the consumer still holds a reference to the
   116     // buffer.
   117     //
   118     // If presentWhen is nonzero, it indicates the time when the buffer will
   119     // be displayed on screen.  If the buffer's timestamp is farther in the
   120     // future, the buffer won't be acquired, and PRESENT_LATER will be
   121     // returned.  The presentation time is in nanoseconds, and the time base
   122     // is CLOCK_MONOTONIC.
   123     virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen) = 0;
   125     // releaseBuffer releases a buffer slot from the consumer back to the
   126     // BufferQueue.  This may be done while the buffer's contents are still
   127     // being accessed.  The fence will signal when the buffer is no longer
   128     // in use. frameNumber is used to indentify the exact buffer returned.
   129     //
   130     // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
   131     // any references to the just-released buffer that it might have, as if it
   132     // had received a onBuffersReleased() call with a mask set for the released
   133     // buffer.
   134     //
   135     // Note that the dependencies on EGL will be removed once we switch to using
   136     // the Android HW Sync HAL.
   137     virtual status_t releaseBuffer(int buf, uint64_t frameNumber, const sp<Fence>& releaseFence) = 0;
   139     // consumerConnect connects a consumer to the BufferQueue.  Only one
   140     // consumer may be connected, and when that consumer disconnects the
   141     // BufferQueue is placed into the "abandoned" state, causing most
   142     // interactions with the BufferQueue by the producer to fail.
   143     // controlledByApp indicates whether the consumer is controlled by
   144     // the application.
   145     //
   146     // consumer may not be NULL.
   147     virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) = 0;
   149     // consumerDisconnect disconnects a consumer from the BufferQueue. All
   150     // buffers will be freed and the BufferQueue is placed in the "abandoned"
   151     // state, causing most interactions with the BufferQueue by the producer to
   152     // fail.
   153     virtual status_t consumerDisconnect() = 0;
   155     // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
   156     // indicating which buffer slots have been released by the BufferQueue
   157     // but have not yet been released by the consumer.
   158     //
   159     // This should be called from the onBuffersReleased() callback.
   160     virtual status_t getReleasedBuffers(uint32_t* slotMask) = 0;
   162     // setDefaultBufferSize is used to set the size of buffers returned by
   163     // dequeueBuffer when a width and height of zero is requested.  Default
   164     // is 1x1.
   165     virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h) = 0;
   167     // setDefaultMaxBufferCount sets the default value for the maximum buffer
   168     // count (the initial default is 2). If the producer has requested a
   169     // buffer count using setBufferCount, the default buffer count will only
   170     // take effect if the producer sets the count back to zero.
   171     //
   172     // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
   173     virtual status_t setDefaultMaxBufferCount(int bufferCount) = 0;
   175     // disableAsyncBuffer disables the extra buffer used in async mode
   176     // (when both producer and consumer have set their "isControlledByApp"
   177     // flag) and has dequeueBuffer() return WOULD_BLOCK instead.
   178     //
   179     // This can only be called before consumerConnect().
   180     virtual status_t disableAsyncBuffer() = 0;
   182     // setMaxAcquiredBufferCount sets the maximum number of buffers that can
   183     // be acquired by the consumer at one time (default 1).  This call will
   184     // fail if a producer is connected to the BufferQueue.
   185     virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) = 0;
   187     // setConsumerName sets the name used in logging
   188     virtual void setConsumerName(const String8& name) = 0;
   190     // setDefaultBufferFormat allows the BufferQueue to create
   191     // GraphicBuffers of a defaultFormat if no format is specified
   192     // in dequeueBuffer.  Formats are enumerated in graphics.h; the
   193     // initial default is HAL_PIXEL_FORMAT_RGBA_8888.
   194     virtual status_t setDefaultBufferFormat(uint32_t defaultFormat) = 0;
   196     // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer.
   197     // These are merged with the bits passed to dequeueBuffer.  The values are
   198     // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
   199     virtual status_t setConsumerUsageBits(uint32_t usage) = 0;
   201     // setTransformHint bakes in rotation to buffers so overlays can be used.
   202     // The values are enumerated in window.h, e.g.
   203     // NATIVE_WINDOW_TRANSFORM_ROT_90.  The default is 0 (no transform).
   204     virtual status_t setTransformHint(uint32_t hint) = 0;
   206     // dump state into a string
   207     virtual void dump(String8& result, const char* prefix) const = 0;
   209 public:
   210     DECLARE_META_INTERFACE(GonkGraphicBufferConsumer);
   211 };
   213 // ----------------------------------------------------------------------------
   215 class BnGonkGraphicBufferConsumer : public BnInterface<IGonkGraphicBufferConsumer>
   216 {
   217 public:
   218     virtual status_t    onTransact( uint32_t code,
   219                                     const Parcel& data,
   220                                     Parcel* reply,
   221                                     uint32_t flags = 0);
   222 };
   224 // ----------------------------------------------------------------------------
   225 }; // namespace android
   227 #endif // ANDROID_GUI_IGRAPHICBUFFERCONSUMER_H

mercurial