diff options
author | Mathias Agopian <mathias@google.com> | 2013-07-20 01:02:47 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-07-20 01:02:47 +0000 |
commit | bdce8170479d0efb548514c1a290e1bfea711cfd (patch) | |
tree | 7cd97ee1e8d8842e3d229a531975f43f4502c75e /include | |
parent | e5bb2a45e0861c7ed953373f86afe44f255f021c (diff) | |
parent | 26a6f37cc06b8014edcedbee8d5558ca7da9abe3 (diff) | |
download | frameworks_native-bdce8170479d0efb548514c1a290e1bfea711cfd.zip frameworks_native-bdce8170479d0efb548514c1a290e1bfea711cfd.tar.gz frameworks_native-bdce8170479d0efb548514c1a290e1bfea711cfd.tar.bz2 |
Merge changes Ic45929f3,Ic63f4f96,I1e703d36,I691f9507
* changes:
make sure to reset the framenumber when a buffer is marked FREE
Make ANW.setSwapInterval(0) work again
BuffferQueue disconnect is now always asynchrnous
BufferQueue improvements and APIs changes
Diffstat (limited to 'include')
-rw-r--r-- | include/gui/BufferItemConsumer.h | 4 | ||||
-rw-r--r-- | include/gui/BufferQueue.h | 80 | ||||
-rw-r--r-- | include/gui/ConsumerBase.h | 4 | ||||
-rw-r--r-- | include/gui/CpuConsumer.h | 2 | ||||
-rw-r--r-- | include/gui/DummyConsumer.h | 46 | ||||
-rw-r--r-- | include/gui/GLConsumer.h | 7 | ||||
-rw-r--r-- | include/gui/IGraphicBufferProducer.h | 26 | ||||
-rw-r--r-- | include/gui/Surface.h | 13 |
8 files changed, 67 insertions, 115 deletions
diff --git a/include/gui/BufferItemConsumer.h b/include/gui/BufferItemConsumer.h index 0af6f8e..9370e81 100644 --- a/include/gui/BufferItemConsumer.h +++ b/include/gui/BufferItemConsumer.h @@ -51,9 +51,11 @@ class BufferItemConsumer: public ConsumerBase // the consumer usage flags passed to the graphics allocator. The // bufferCount parameter specifies how many buffers can be locked for user // access at the same time. + // controlledByApp tells whether this consumer is controlled by the + // application. BufferItemConsumer(const sp<BufferQueue>& bq, uint32_t consumerUsage, int bufferCount = BufferQueue::MIN_UNDEQUEUED_BUFFERS, - bool synchronousMode = false); + bool controlledByApp = false); virtual ~BufferItemConsumer(); diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h index 0143be3..628678f 100644 --- a/include/gui/BufferQueue.h +++ b/include/gui/BufferQueue.h @@ -97,11 +97,9 @@ public: // BufferQueue manages a pool of gralloc memory slots to be used by - // producers and consumers. allowSynchronousMode specifies whether or not - // synchronous mode can be enabled by the producer. allocator is used to - // allocate all the needed gralloc buffers. - BufferQueue(bool allowSynchronousMode = true, - const sp<IGraphicBufferAlloc>& allocator = NULL); + // producers and consumers. allocator is used to allocate all the + // needed gralloc buffers. + BufferQueue(const sp<IGraphicBufferAlloc>& allocator = NULL); virtual ~BufferQueue(); // Query native window attributes. The "what" values are enumerated in @@ -169,7 +167,7 @@ public: // // In both cases, the producer will need to call requestBuffer to get a // GraphicBuffer handle for the returned slot. - virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, + virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async, uint32_t width, uint32_t height, uint32_t format, uint32_t usage); // queueBuffer returns a filled buffer to the BufferQueue. @@ -197,15 +195,6 @@ public: // will usually be the one obtained from dequeueBuffer. virtual void cancelBuffer(int buf, const sp<Fence>& fence); - // setSynchronousMode sets whether dequeueBuffer is synchronous or - // asynchronous. In synchronous mode, dequeueBuffer blocks until - // a buffer is available, the currently bound buffer can be dequeued and - // queued buffers will be acquired in order. In asynchronous mode, - // a queued buffer may be replaced by a subsequently queued buffer. - // - // The default mode is asynchronous. - virtual status_t setSynchronousMode(bool enabled); - // connect attempts to connect a producer API to the BufferQueue. This // must be called before any other IGraphicBufferProducer methods are // called except for getAllocator. A consumer must already be connected. @@ -215,7 +204,7 @@ public: // it's still connected to a producer). // // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU). - virtual status_t connect(int api, QueueBufferOutput* output); + virtual status_t connect(int api, bool producerControlledByApp, QueueBufferOutput* output); // disconnect attempts to disconnect a producer API from the BufferQueue. // Calling this method will cause any subsequent calls to other @@ -234,13 +223,13 @@ public: // public facing structure for BufferSlot struct BufferItem { - BufferItem() - : + BufferItem() : mTransform(0), mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), mTimestamp(0), mFrameNumber(0), mBuf(INVALID_BUFFER_SLOT), + mIsDroppable(false), mAcquireCalled(false) { mCrop.makeInvalid(); } @@ -271,6 +260,13 @@ public: // mFence is a fence that will signal when the buffer is idle. sp<Fence> mFence; + // mIsDroppable whether this buffer was queued with the + // property that it can be replaced by a new buffer for the purpose of + // making sure dequeueBuffer() won't block. + // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer + // was queued. + bool mIsDroppable; + // Indicates whether this buffer has been seen by a consumer yet bool mAcquireCalled; }; @@ -312,9 +308,11 @@ public: // consumer may be connected, and when that consumer disconnects the // BufferQueue is placed into the "abandoned" state, causing most // interactions with the BufferQueue by the producer to fail. + // controlledByApp indicates whether the consumer is controlled by + // the application. // // consumer may not be NULL. - status_t consumerConnect(const sp<ConsumerListener>& consumer); + status_t consumerConnect(const sp<ConsumerListener>& consumer, bool controlledByApp); // consumerDisconnect disconnects a consumer from the BufferQueue. All // buffers will be freed and the BufferQueue is placed in the "abandoned" @@ -347,10 +345,6 @@ public: // fail if a producer is connected to the BufferQueue. status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); - // isSynchronousMode returns whether the BufferQueue is currently in - // synchronous mode. - bool isSynchronousMode() const; - // setConsumerName sets the name used in logging void setConsumerName(const String8& name); @@ -379,43 +373,35 @@ private: // all slots. void freeAllBuffersLocked(); - // drainQueueLocked waits for the buffer queue to empty if we're in - // synchronous mode, or returns immediately otherwise. It returns NO_INIT - // if the BufferQueue is abandoned (consumer disconnected) or disconnected - // (producer disconnected) during the call. - status_t drainQueueLocked(); - - // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in - // synchronous mode and free all buffers. In asynchronous mode, all buffers - // are freed except the currently queued buffer (if it exists). - status_t drainQueueAndFreeBuffersLocked(); - // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots // that will be used if the producer does not override the buffer slot // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. // The initial default is 2. status_t setDefaultMaxBufferCountLocked(int count); + // getMinUndequeuedBufferCount returns the minimum number of buffers + // that must remain in a state other than DEQUEUED. + // The async parameter tells whether we're in asynchronous mode. + int getMinUndequeuedBufferCount(bool async) const; + // getMinBufferCountLocked returns the minimum number of buffers allowed // given the current BufferQueue state. - int getMinMaxBufferCountLocked() const; - - // getMinUndequeuedBufferCountLocked returns the minimum number of buffers - // that must remain in a state other than DEQUEUED. - int getMinUndequeuedBufferCountLocked() const; + // The async parameter tells whether we're in asynchronous mode. + int getMinMaxBufferCountLocked(bool async) const; // getMaxBufferCountLocked returns the maximum number of buffers that can // be allocated at once. This value depends upon the following member // variables: // - // mSynchronousMode + // mDequeueBufferCannotBlock // mMaxAcquiredBufferCount // mDefaultMaxBufferCount // mOverrideMaxBufferCount + // async parameter // // Any time one of these member variables is changed while a producer is // connected, mDequeueCondition must be broadcast. - int getMaxBufferCountLocked() const; + int getMaxBufferCountLocked(bool async) const; // stillTracking returns true iff the buffer item is still being tracked // in one of the slots. @@ -568,12 +554,14 @@ private: // to NULL and is written by consumerConnect and consumerDisconnect. sp<ConsumerListener> mConsumerListener; - // mSynchronousMode whether we're in synchronous mode or not - bool mSynchronousMode; + // mConsumerControlledByApp whether the connected consumer is controlled by the + // application. + bool mConsumerControlledByApp; - // mAllowSynchronousMode whether we allow synchronous mode or not. Set - // when the BufferQueue is created (by the consumer). - const bool mAllowSynchronousMode; + // mDequeueBufferCannotBlock whether dequeueBuffer() isn't allowed to block. + // this flag is set durring connect() when both consumer and producer are controlled + // by the application. + bool mDequeueBufferCannotBlock; // mConnectedApi indicates the producer API that is currently connected // to this BufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets diff --git a/include/gui/ConsumerBase.h b/include/gui/ConsumerBase.h index 42b84cc..7b58bc5 100644 --- a/include/gui/ConsumerBase.h +++ b/include/gui/ConsumerBase.h @@ -87,7 +87,9 @@ protected: // ConsumerBase constructs a new ConsumerBase object to consume image // buffers from the given BufferQueue. - ConsumerBase(const sp<BufferQueue> &bufferQueue); + // The controlledByApp flag indicates that this consumer is under the application's + // control. + ConsumerBase(const sp<BufferQueue> &bufferQueue, bool controlledByApp = false); // onLastStrongRef gets called by RefBase just before the dtor of the most // derived class. It is used to clean up the buffers so that ConsumerBase diff --git a/include/gui/CpuConsumer.h b/include/gui/CpuConsumer.h index 5f1e369..2890350 100644 --- a/include/gui/CpuConsumer.h +++ b/include/gui/CpuConsumer.h @@ -67,7 +67,7 @@ class CpuConsumer : public ConsumerBase // Create a new CPU consumer. The maxLockedBuffers parameter specifies // how many buffers can be locked for user access at the same time. CpuConsumer(const sp<BufferQueue>& bq, - uint32_t maxLockedBuffers, bool synchronousMode = true); + uint32_t maxLockedBuffers, bool controlledByApp = false); virtual ~CpuConsumer(); diff --git a/include/gui/DummyConsumer.h b/include/gui/DummyConsumer.h deleted file mode 100644 index 08e8ec8..0000000 --- a/include/gui/DummyConsumer.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#ifndef ANDROID_GUI_DUMMYCONSUMER_H -#define ANDROID_GUI_DUMMYCONSUMER_H - -#include <gui/BufferQueue.h> - -namespace android { -// ---------------------------------------------------------------------------- - - -// The DummyConsumer does not keep a reference to BufferQueue -// unlike GLConsumer. This prevents a circular reference from -// forming without having to use a ProxyConsumerListener -class DummyConsumer : public BufferQueue::ConsumerListener { -public: - DummyConsumer(); - virtual ~DummyConsumer(); -protected: - - // Implementation of the BufferQueue::ConsumerListener interface. These - // calls are used to notify the GLConsumer of asynchronous events in the - // BufferQueue. - virtual void onFrameAvailable(); - virtual void onBuffersReleased(); - -}; - -// ---------------------------------------------------------------------------- -}; // namespace android - -#endif // ANDROID_GUI_DUMMYCONSUMER_H diff --git a/include/gui/GLConsumer.h b/include/gui/GLConsumer.h index 65544bd..1df5b42 100644 --- a/include/gui/GLConsumer.h +++ b/include/gui/GLConsumer.h @@ -87,7 +87,7 @@ public: // requirement that either of these methods be called. GLConsumer(const sp<BufferQueue>& bq, GLuint tex, GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, - bool useFenceSync = true); + bool useFenceSync = true, bool isControlledByApp = false); // updateTexImage acquires the most recently queued buffer, and sets the // image contents of the target texture to it. @@ -177,10 +177,6 @@ public: // current texture buffer. status_t doGLFenceWait() const; - // isSynchronousMode returns whether the GLConsumer is currently in - // synchronous mode. - bool isSynchronousMode() const; - // set the name of the GLConsumer that will be used to identify it in // log messages. void setName(const String8& name); @@ -190,7 +186,6 @@ public: status_t setDefaultBufferFormat(uint32_t defaultFormat); status_t setConsumerUsageBits(uint32_t usage); status_t setTransformHint(uint32_t hint); - virtual status_t setSynchronousMode(bool enabled); // getBufferQueue returns the BufferQueue object to which this // GLConsumer is connected. diff --git a/include/gui/IGraphicBufferProducer.h b/include/gui/IGraphicBufferProducer.h index 29c7ff3..9677962 100644 --- a/include/gui/IGraphicBufferProducer.h +++ b/include/gui/IGraphicBufferProducer.h @@ -84,7 +84,10 @@ public: // 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. - virtual status_t dequeueBuffer(int *slot, sp<Fence>* fence, + // + // 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, uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0; // queueBuffer indicates that the client has finished filling in the @@ -96,6 +99,8 @@ public: // must be monotonically increasing. Its other properties (zero point, etc) // are client-dependent, and should be documented by the client. // + // The async parameter sets whether we're queuing a buffer in asynchronous mode. + // // outWidth, outHeight and outTransform are filled with the default width // and height of the window and current transform applied to buffers, // respectively. @@ -103,17 +108,18 @@ public: struct QueueBufferInput : public Flattenable { inline QueueBufferInput(const Parcel& parcel); inline QueueBufferInput(int64_t timestamp, - const Rect& crop, int scalingMode, uint32_t transform, - sp<Fence> fence) + const Rect& crop, int scalingMode, uint32_t transform, bool async, + const sp<Fence>& fence) : timestamp(timestamp), crop(crop), scalingMode(scalingMode), - transform(transform), fence(fence) { } + transform(transform), async(async), fence(fence) { } inline void deflate(int64_t* outTimestamp, Rect* outCrop, - int* outScalingMode, uint32_t* outTransform, + int* outScalingMode, uint32_t* outTransform, bool* outAsync, sp<Fence>* outFence) const { *outTimestamp = timestamp; *outCrop = crop; *outScalingMode = scalingMode; *outTransform = transform; + *outAsync = bool(async); *outFence = fence; } @@ -130,6 +136,7 @@ public: Rect crop; int scalingMode; uint32_t transform; + int async; sp<Fence> fence; }; @@ -171,13 +178,6 @@ public: // 'what' tokens allowed are that of android_natives.h virtual int query(int what, int* value) = 0; - // setSynchronousMode set whether dequeueBuffer is synchronous or - // asynchronous. In synchronous mode, dequeueBuffer blocks until - // a buffer is available, the currently bound buffer can be dequeued and - // queued buffers will be retired in order. - // The default mode is asynchronous. - virtual status_t setSynchronousMode(bool enabled) = 0; - // connect attempts to connect a client API to the IGraphicBufferProducer. // This must be called before any other IGraphicBufferProducer methods are // called except for getAllocator. @@ -188,7 +188,7 @@ public: // outWidth, outHeight and outTransform are filled with the default width // and height of the window and current transform applied to buffers, // respectively. - virtual status_t connect(int api, QueueBufferOutput* output) = 0; + virtual status_t connect(int api, bool producerControlledByApp, QueueBufferOutput* output) = 0; // disconnect attempts to disconnect a client API from the // IGraphicBufferProducer. Calling this method will cause any subsequent diff --git a/include/gui/Surface.h b/include/gui/Surface.h index c25847c..2f7406e 100644 --- a/include/gui/Surface.h +++ b/include/gui/Surface.h @@ -61,8 +61,11 @@ public: * However, once a Surface is connected, it'll prevent other Surfaces * referring to the same IGraphicBufferProducer to become connected and * therefore prevent them to be used as actual producers of buffers. + * + * the controlledByApp flag indicates that this Surface (producer) is + * controlled by the application. This flag is used at connect time. */ - Surface(const sp<IGraphicBufferProducer>& bufferProducer); + Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false); /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this * Surface was created with. Usually it's an error to use the @@ -228,6 +231,14 @@ private: // window. this is only a hint, actual transform may differ. uint32_t mTransformHint; + // mProducerControlledByApp whether this buffer producer is controlled + // by the application + bool mProducerControlledByApp; + + // mSwapIntervalZero set if we should drop buffers at queue() time to + // achieve an asynchronous swap interval + bool mSwapIntervalZero; + // mConsumerRunningBehind whether the consumer is running more than // one buffer behind the producer. mutable bool mConsumerRunningBehind; |