• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 
17 #pragma once
18 
19 #include <utils/Errors.h>
20 #include <utils/RefBase.h>
21 
22 #include <cstdint>
23 
24 #include <com_android_graphics_libgui_flags.h>
25 
26 namespace android {
27 
28 class BufferItem;
29 class FrameEventHistoryDelta;
30 struct NewFrameEventsEntry;
31 
32 // ConsumerListener is the interface through which the BufferQueue notifies the consumer of events
33 // that the consumer may wish to react to. Because the consumer will generally have a mutex that is
34 // locked during calls from the consumer to the BufferQueue, these calls from the BufferQueue to the
35 // consumer *MUST* be called only when the BufferQueue mutex is NOT locked.
36 
37 class ConsumerListener : public virtual RefBase {
38 public:
ConsumerListener()39     ConsumerListener() {}
40     virtual ~ConsumerListener();
41 
42     // onDisconnect is called when a producer disconnects from the BufferQueue.
onDisconnect()43     virtual void onDisconnect() {} /* Asynchronous */
44 
45     // onFrameDequeued is called when a call to the BufferQueueProducer::dequeueBuffer successfully
46     // returns a slot from the BufferQueue.
onFrameDequeued(const uint64_t)47     virtual void onFrameDequeued(const uint64_t) {}
48 
49     // onFrameCancelled is called when the client calls cancelBuffer, thereby releasing the slot
50     // back to the BufferQueue.
onFrameCancelled(const uint64_t)51     virtual void onFrameCancelled(const uint64_t) {}
52 
53     // onFrameDetached is called after a successful detachBuffer() call while in asynchronous mode.
onFrameDetached(const uint64_t)54     virtual void onFrameDetached(const uint64_t) {}
55 
56     // onFrameAvailable is called from queueBuffer each time an additional frame becomes available
57     // for consumption. This means that frames that are queued while in asynchronous mode only
58     // trigger the callback if no previous frames are pending. Frames queued while in synchronous
59     // mode always trigger the callback. The item passed to the callback will contain all of the
60     // information about the queued frame except for its GraphicBuffer pointer, which will always be
61     // null (except if the consumer is SurfaceFlinger).
62     //
63     // This is called without any lock held and can be called concurrently by multiple threads.
64     virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */
65 
66     // onFrameReplaced is called from queueBuffer if the frame being queued is replacing an existing
67     // slot in the queue. Any call to queueBuffer that doesn't call onFrameAvailable will call this
68     // callback instead. The item passed to the callback will contain all of the information about
69     // the queued frame except for its GraphicBuffer pointer, which will always be null.
70     //
71     // This is called without any lock held and can be called concurrently by multiple threads.
onFrameReplaced(const BufferItem &)72     virtual void onFrameReplaced(const BufferItem& /* item */) {} /* Asynchronous */
73 
74     // onBuffersReleased is called to notify the buffer consumer that the BufferQueue has released
75     // its references to one or more GraphicBuffers contained in its slots. The buffer consumer
76     // should then call BufferQueue::getReleasedBuffers to retrieve the list of buffers.
77     //
78     // This is called without any lock held and can be called concurrently by multiple threads.
79     virtual void onBuffersReleased() = 0; /* Asynchronous */
80 
81     // onSidebandStreamChanged is called to notify the buffer consumer that the BufferQueue's
82     // sideband buffer stream has changed. This is called when a stream is first attached and when
83     // it is either detached or replaced by a different stream.
84     virtual void onSidebandStreamChanged() = 0; /* Asynchronous */
85 
86     // Notifies the consumer of any new producer-side timestamps and returns the combined frame
87     // history that hasn't already been retrieved.
88     //
89     // WARNING: This method can only be called when the BufferQueue is in the consumer's process.
addAndGetFrameTimestamps(const NewFrameEventsEntry *,FrameEventHistoryDelta *)90     virtual void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/,
91                                           FrameEventHistoryDelta* /*outDelta*/) {}
92 
93 #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_SETFRAMERATE)
94     // Notifies the consumer of a setFrameRate call from the producer side.
onSetFrameRate(float,int8_t,int8_t)95     virtual void onSetFrameRate(float /*frameRate*/, int8_t /*compatibility*/,
96                                 int8_t /*changeFrameRateStrategy*/) {}
97 #endif
98 
99 #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_UNLIMITED_SLOTS)
100     // Notifies the consumer that IGraphicBufferProducer::extendSlotCount has
101     // been called and the total slot count has increased.
102     //
103     // This will only ever be called if
104     // IGraphicBufferConsumer::allowUnlimitedSlots has been called on the
105     // consumer.
onSlotCountChanged(int)106     virtual void onSlotCountChanged(int /* slotCount */) {}
107 #endif
108 };
109 
110 class IConsumerListener : public ConsumerListener {};
111 
112 } // namespace android
113