Home | History | Annotate | Download | only in gui
      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 #ifndef ANDROID_GUI_ICONSUMERLISTENER_H
     18 #define ANDROID_GUI_ICONSUMERLISTENER_H
     19 
     20 #include <stdint.h>
     21 #include <sys/types.h>
     22 
     23 #include <utils/Errors.h>
     24 #include <utils/RefBase.h>
     25 
     26 #include <binder/IInterface.h>
     27 
     28 #include <gui/FrameTimestamps.h>
     29 
     30 namespace android {
     31 // ----------------------------------------------------------------------------
     32 
     33 class BufferItem;
     34 
     35 // ConsumerListener is the interface through which the BufferQueue notifies
     36 // the consumer of events that the consumer may wish to react to.  Because
     37 // the consumer will generally have a mutex that is locked during calls from
     38 // the consumer to the BufferQueue, these calls from the BufferQueue to the
     39 // consumer *MUST* be called only when the BufferQueue mutex is NOT locked.
     40 
     41 class ConsumerListener : public virtual RefBase {
     42 public:
     43     ConsumerListener() { }
     44     virtual ~ConsumerListener() { }
     45 
     46     // onFrameAvailable is called from queueBuffer each time an additional
     47     // frame becomes available for consumption. This means that frames that
     48     // are queued while in asynchronous mode only trigger the callback if no
     49     // previous frames are pending. Frames queued while in synchronous mode
     50     // always trigger the callback. The item passed to the callback will contain
     51     // all of the information about the queued frame except for its
     52     // GraphicBuffer pointer, which will always be null.
     53     //
     54     // This is called without any lock held and can be called concurrently
     55     // by multiple threads.
     56     virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */
     57 
     58     // onFrameReplaced is called from queueBuffer if the frame being queued is
     59     // replacing an existing slot in the queue. Any call to queueBuffer that
     60     // doesn't call onFrameAvailable will call this callback instead. The item
     61     // passed to the callback will contain all of the information about the
     62     // queued frame except for its GraphicBuffer pointer, which will always be
     63     // null.
     64     //
     65     // This is called without any lock held and can be called concurrently
     66     // by multiple threads.
     67     virtual void onFrameReplaced(const BufferItem& /* item */) {} /* Asynchronous */
     68 
     69     // onBuffersReleased is called to notify the buffer consumer that the
     70     // BufferQueue has released its references to one or more GraphicBuffers
     71     // contained in its slots.  The buffer consumer should then call
     72     // BufferQueue::getReleasedBuffers to retrieve the list of buffers
     73     //
     74     // This is called without any lock held and can be called concurrently
     75     // by multiple threads.
     76     virtual void onBuffersReleased() = 0; /* Asynchronous */
     77 
     78     // onSidebandStreamChanged is called to notify the buffer consumer that the
     79     // BufferQueue's sideband buffer stream has changed. This is called when a
     80     // stream is first attached and when it is either detached or replaced by a
     81     // different stream.
     82     virtual void onSidebandStreamChanged() = 0; /* Asynchronous */
     83 
     84     // See IGraphicBufferProducer::getFrameTimestamps
     85     // This queries the consumer for the timestamps
     86     virtual bool getFrameTimestamps(uint64_t /*frameNumber*/,
     87             FrameTimestamps* /*outTimestamps*/) const { return false; }
     88 };
     89 
     90 
     91 class IConsumerListener : public ConsumerListener, public IInterface
     92 {
     93 public:
     94     DECLARE_META_INTERFACE(ConsumerListener);
     95 };
     96 
     97 // ----------------------------------------------------------------------------
     98 
     99 class BnConsumerListener : public BnInterface<IConsumerListener>
    100 {
    101 public:
    102     virtual status_t    onTransact( uint32_t code,
    103                                     const Parcel& data,
    104                                     Parcel* reply,
    105                                     uint32_t flags = 0);
    106 };
    107 
    108 // ----------------------------------------------------------------------------
    109 }; // namespace android
    110 
    111 #endif // ANDROID_GUI_ICONSUMERLISTENER_H
    112