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

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

mercurial