IConsumerListener.h revision e7df8368652eb4b8cef377182c3d04436b1b7513
1a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian/*
2a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Copyright (C) 2013 The Android Open Source Project
3a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian *
4a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * you may not use this file except in compliance with the License.
6a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * You may obtain a copy of the License at
7a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian *
8a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian *
10a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Unless required by applicable law or agreed to in writing, software
11a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * See the License for the specific language governing permissions and
14a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * limitations under the License.
15a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian */
16a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
17a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#ifndef ANDROID_GUI_ICONSUMERLISTENER_H
18a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#define ANDROID_GUI_ICONSUMERLISTENER_H
19a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
20e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza#include <gui/FrameTimestamps.h>
21e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza
22e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza#include <binder/IInterface.h>
23a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
24a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <utils/Errors.h>
25a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <utils/RefBase.h>
26a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
27e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza#include <stdint.h>
28e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza#include <sys/types.h>
29ce796e78a57018f186b062199c75d94545318acaPablo Ceballos
30a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopiannamespace android {
31a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
328dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stozaclass BufferItem;
338dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza
34e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza// ConsumerListener is the interface through which the BufferQueue notifies the consumer of events
35e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza// that the consumer may wish to react to. Because the consumer will generally have a mutex that is
36e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza// locked during calls from the consumer to the BufferQueue, these calls from the BufferQueue to the
37a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// consumer *MUST* be called only when the BufferQueue mutex is NOT locked.
38a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
39a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianclass ConsumerListener : public virtual RefBase {
40a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic:
41e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    ConsumerListener() {}
4297b64dbe717b7daf29962f44c1b621c633473556Colin Cross    virtual ~ConsumerListener();
43a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
445ea5e5905170f32d5cf45ad35c552d64743892c3Brian Anderson    // onDisconnect is called when a producer disconnects from the BufferQueue.
455ea5e5905170f32d5cf45ad35c552d64743892c3Brian Anderson    virtual void onDisconnect() {} /* Asynchronous */
465ea5e5905170f32d5cf45ad35c552d64743892c3Brian Anderson
47e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // onFrameAvailable is called from queueBuffer each time an additional frame becomes available
48e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // for consumption. This means that frames that are queued while in asynchronous mode only
49e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // trigger the callback if no previous frames are pending. Frames queued while in synchronous
50e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // mode always trigger the callback. The item passed to the callback will contain all of the
51e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // information about the queued frame except for its GraphicBuffer pointer, which will always be
52e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // null (except if the consumer is SurfaceFlinger).
538dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    //
54e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // This is called without any lock held and can be called concurrently by multiple threads.
558dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza    virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */
568dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza
57e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // onFrameReplaced is called from queueBuffer if the frame being queued is replacing an existing
58e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // slot in the queue. Any call to queueBuffer that doesn't call onFrameAvailable will call this
59e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // callback instead. The item passed to the callback will contain all of the information about
60e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // the queued frame except for its GraphicBuffer pointer, which will always be null.
61a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian    //
62e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // This is called without any lock held and can be called concurrently by multiple threads.
63a32900deec6284973100a29f7b399d061f82b3a8Andreas Gampe    virtual void onFrameReplaced(const BufferItem& /* item */) {} /* Asynchronous */
64a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
65e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // onBuffersReleased is called to notify the buffer consumer that the BufferQueue has released
66e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // its references to one or more GraphicBuffers contained in its slots. The buffer consumer
67e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // should then call BufferQueue::getReleasedBuffers to retrieve the list of buffers.
68a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian    //
69e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // This is called without any lock held and can be called concurrently by multiple threads.
70a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian    virtual void onBuffersReleased() = 0; /* Asynchronous */
71399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall
72e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // onSidebandStreamChanged is called to notify the buffer consumer that the BufferQueue's
73e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // sideband buffer stream has changed. This is called when a stream is first attached and when
74e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // it is either detached or replaced by a different stream.
75399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    virtual void onSidebandStreamChanged() = 0; /* Asynchronous */
76ce796e78a57018f186b062199c75d94545318acaPablo Ceballos
77e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // Notifies the consumer of any new producer-side timestamps and returns the combined frame
78e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    // history that hasn't already been retrieved.
79e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    virtual void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/,
80e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza                                          FrameEventHistoryDelta* /*outDelta*/) {}
81a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian};
82a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
83e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stozaclass IConsumerListener : public ConsumerListener, public IInterface {
84a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic:
8517576de056a57753eb4af797545db88ef4f81ef0Colin Cross    DECLARE_META_INTERFACE(ConsumerListener)
86a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian};
87a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
88e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stozaclass BnConsumerListener : public BnInterface<IConsumerListener> {
89a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic:
90e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza    virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
91e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza                                uint32_t flags = 0);
92a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian};
93a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
94e7df8368652eb4b8cef377182c3d04436b1b7513Dan Stoza} // namespace android
95a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian
96a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#endif // ANDROID_GUI_ICONSUMERLISTENER_H
97