• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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_IPRODUCERLISTENER_H
18 #define ANDROID_GUI_IPRODUCERLISTENER_H
19 
20 #include <vector>
21 
22 #include <android/hardware/graphics/bufferqueue/1.0/IProducerListener.h>
23 #include <android/hardware/graphics/bufferqueue/2.0/IProducerListener.h>
24 #include <binder/IInterface.h>
25 #include <hidl/HybridInterface.h>
26 #include <utils/RefBase.h>
27 
28 namespace android {
29 
30 // ProducerListener is the interface through which the BufferQueue notifies the
31 // producer of events that the producer may wish to react to. Because the
32 // producer will generally have a mutex that is locked during calls from the
33 // producer to the BufferQueue, these calls from the BufferQueue to the
34 // producer *MUST* be called only when the BufferQueue mutex is NOT locked.
35 
36 class ProducerListener : public virtual RefBase
37 {
38 public:
ProducerListener()39     ProducerListener() {}
40     virtual ~ProducerListener();
41 
42     // onBufferReleased is called from IGraphicBufferConsumer::releaseBuffer to
43     // notify the producer that a new buffer is free and ready to be dequeued.
44     //
45     // This is called without any lock held and can be called concurrently by
46     // multiple threads.
47     virtual void onBufferReleased() = 0; // Asynchronous
48     virtual bool needsReleaseNotify() = 0;
49     // onBuffersFreed is called from IGraphicBufferConsumer::discardFreeBuffers
50     // to notify the producer that certain free buffers are discarded by the consumer.
51     virtual void onBuffersDiscarded(const std::vector<int32_t>& slots) = 0; // Asynchronous
52     // onBufferDetached is called from IGraphicBufferConsumer::detachBuffer to
53     // notify the producer that a buffer slot is free and ready to be dequeued.
54     //
55     // This is called without any lock held and can be called concurrently by
56     // multiple threads.
onBufferDetached(int)57     virtual void onBufferDetached(int /*slot*/) {} // Asynchronous
58 };
59 
60 #ifndef NO_BINDER
61 class IProducerListener : public ProducerListener, public IInterface
62 {
63 public:
64     using HProducerListener1 =
65             ::android::hardware::graphics::bufferqueue::V1_0::IProducerListener;
66     using HProducerListener2 =
67             ::android::hardware::graphics::bufferqueue::V2_0::IProducerListener;
68     DECLARE_HYBRID_META_INTERFACE(
69             ProducerListener,
70             HProducerListener1,
71             HProducerListener2)
72 };
73 
74 class BnProducerListener : public BnInterface<IProducerListener>
75 {
76 public:
77     virtual status_t onTransact(uint32_t code, const Parcel& data,
78             Parcel* reply, uint32_t flags = 0);
79     virtual bool needsReleaseNotify();
80     virtual void onBuffersDiscarded(const std::vector<int32_t>& slots);
81 };
82 
83 #else
84 class IProducerListener : public ProducerListener {
85 };
86 class BnProducerListener : public IProducerListener {
87 };
88 #endif
89 class StubProducerListener : public BnProducerListener {
90 public:
91     virtual ~StubProducerListener();
onBufferReleased()92     virtual void onBufferReleased() {}
needsReleaseNotify()93     virtual bool needsReleaseNotify() { return false; }
94 };
95 
96 } // namespace android
97 
98 #endif
99