xref: /aosp_15_r20/frameworks/native/include/gui/Surface.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2010 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_GUI_SURFACE_H
18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_GUI_SURFACE_H
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/FrameTimelineInfo.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <com_android_graphics_libgui_flags.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <gui/BufferQueueDefs.h>
23*38e8c45fSAndroid Build Coastguard Worker #include <gui/HdrMetadata.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <gui/IGraphicBufferProducer.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <gui/IProducerListener.h>
26*38e8c45fSAndroid Build Coastguard Worker #include <system/window.h>
27*38e8c45fSAndroid Build Coastguard Worker #include <ui/ANativeObjectBase.h>
28*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicTypes.h>
29*38e8c45fSAndroid Build Coastguard Worker #include <ui/Region.h>
30*38e8c45fSAndroid Build Coastguard Worker #include <utils/Condition.h>
31*38e8c45fSAndroid Build Coastguard Worker #include <utils/Mutex.h>
32*38e8c45fSAndroid Build Coastguard Worker #include <utils/RefBase.h>
33*38e8c45fSAndroid Build Coastguard Worker 
34*38e8c45fSAndroid Build Coastguard Worker #include <shared_mutex>
35*38e8c45fSAndroid Build Coastguard Worker #include <unordered_set>
36*38e8c45fSAndroid Build Coastguard Worker 
37*38e8c45fSAndroid Build Coastguard Worker namespace android {
38*38e8c45fSAndroid Build Coastguard Worker 
39*38e8c45fSAndroid Build Coastguard Worker class GraphicBuffer;
40*38e8c45fSAndroid Build Coastguard Worker 
41*38e8c45fSAndroid Build Coastguard Worker namespace gui {
42*38e8c45fSAndroid Build Coastguard Worker class ISurfaceComposer;
43*38e8c45fSAndroid Build Coastguard Worker } // namespace gui
44*38e8c45fSAndroid Build Coastguard Worker 
45*38e8c45fSAndroid Build Coastguard Worker class ISurfaceComposer;
46*38e8c45fSAndroid Build Coastguard Worker 
47*38e8c45fSAndroid Build Coastguard Worker using gui::FrameTimelineInfo;
48*38e8c45fSAndroid Build Coastguard Worker 
49*38e8c45fSAndroid Build Coastguard Worker /* This is the same as ProducerListener except that onBuffersDiscarded is
50*38e8c45fSAndroid Build Coastguard Worker  * called with a vector of graphic buffers instead of buffer slots.
51*38e8c45fSAndroid Build Coastguard Worker  */
52*38e8c45fSAndroid Build Coastguard Worker class SurfaceListener : public virtual RefBase
53*38e8c45fSAndroid Build Coastguard Worker {
54*38e8c45fSAndroid Build Coastguard Worker public:
55*38e8c45fSAndroid Build Coastguard Worker     SurfaceListener() = default;
56*38e8c45fSAndroid Build Coastguard Worker     virtual ~SurfaceListener() = default;
57*38e8c45fSAndroid Build Coastguard Worker 
58*38e8c45fSAndroid Build Coastguard Worker     virtual void onBufferReleased() = 0;
59*38e8c45fSAndroid Build Coastguard Worker     virtual bool needsReleaseNotify() = 0;
60*38e8c45fSAndroid Build Coastguard Worker 
61*38e8c45fSAndroid Build Coastguard Worker     virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& buffers) = 0;
62*38e8c45fSAndroid Build Coastguard Worker     virtual void onBufferDetached(int slot) = 0;
63*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_CONSUMER_ATTACH_CALLBACK)
onBufferAttached()64*38e8c45fSAndroid Build Coastguard Worker     virtual void onBufferAttached() {}
needsAttachNotify()65*38e8c45fSAndroid Build Coastguard Worker     virtual bool needsAttachNotify() { return false; }
66*38e8c45fSAndroid Build Coastguard Worker #endif
67*38e8c45fSAndroid Build Coastguard Worker 
68*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
69*38e8c45fSAndroid Build Coastguard Worker     // Called if this Surface is connected to a remote implementation and it
70*38e8c45fSAndroid Build Coastguard Worker     // dies or becomes unavailable.
onRemoteDied()71*38e8c45fSAndroid Build Coastguard Worker     virtual void onRemoteDied() {}
72*38e8c45fSAndroid Build Coastguard Worker 
73*38e8c45fSAndroid Build Coastguard Worker     // Clients will overwrite this if they want to receive a notification
74*38e8c45fSAndroid Build Coastguard Worker     // via onRemoteDied. This should return a constant value.
needsDeathNotify()75*38e8c45fSAndroid Build Coastguard Worker     virtual bool needsDeathNotify() { return false; }
76*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
77*38e8c45fSAndroid Build Coastguard Worker };
78*38e8c45fSAndroid Build Coastguard Worker 
79*38e8c45fSAndroid Build Coastguard Worker class StubSurfaceListener : public SurfaceListener {
80*38e8c45fSAndroid Build Coastguard Worker public:
~StubSurfaceListener()81*38e8c45fSAndroid Build Coastguard Worker     virtual ~StubSurfaceListener() {}
onBufferReleased()82*38e8c45fSAndroid Build Coastguard Worker     virtual void onBufferReleased() override {}
needsReleaseNotify()83*38e8c45fSAndroid Build Coastguard Worker     virtual bool needsReleaseNotify() { return false; }
onBuffersDiscarded(const std::vector<sp<GraphicBuffer>> &)84*38e8c45fSAndroid Build Coastguard Worker     virtual void onBuffersDiscarded(const std::vector<sp<GraphicBuffer>>& /*buffers*/) override {}
onBufferDetached(int)85*38e8c45fSAndroid Build Coastguard Worker     virtual void onBufferDetached(int /*slot*/) override {}
86*38e8c45fSAndroid Build Coastguard Worker };
87*38e8c45fSAndroid Build Coastguard Worker 
88*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
89*38e8c45fSAndroid Build Coastguard Worker // Contains additional data from the queueBuffer operation.
90*38e8c45fSAndroid Build Coastguard Worker struct SurfaceQueueBufferOutput {
91*38e8c45fSAndroid Build Coastguard Worker     // True if this queueBuffer caused a buffer to be replaced in the queue
92*38e8c45fSAndroid Build Coastguard Worker     // (and therefore not will not be acquired)
93*38e8c45fSAndroid Build Coastguard Worker     bool bufferReplaced = false;
94*38e8c45fSAndroid Build Coastguard Worker };
95*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
96*38e8c45fSAndroid Build Coastguard Worker 
97*38e8c45fSAndroid Build Coastguard Worker /*
98*38e8c45fSAndroid Build Coastguard Worker  * An implementation of ANativeWindow that feeds graphics buffers into a
99*38e8c45fSAndroid Build Coastguard Worker  * BufferQueue.
100*38e8c45fSAndroid Build Coastguard Worker  *
101*38e8c45fSAndroid Build Coastguard Worker  * This is typically used by programs that want to render frames through
102*38e8c45fSAndroid Build Coastguard Worker  * some means (maybe OpenGL, a software renderer, or a hardware decoder)
103*38e8c45fSAndroid Build Coastguard Worker  * and have the frames they create forwarded to SurfaceFlinger for
104*38e8c45fSAndroid Build Coastguard Worker  * compositing.  For example, a video decoder could render a frame and call
105*38e8c45fSAndroid Build Coastguard Worker  * eglSwapBuffers(), which invokes ANativeWindow callbacks defined by
106*38e8c45fSAndroid Build Coastguard Worker  * Surface.  Surface then forwards the buffers through Binder IPC
107*38e8c45fSAndroid Build Coastguard Worker  * to the BufferQueue's producer interface, providing the new frame to a
108*38e8c45fSAndroid Build Coastguard Worker  * consumer such as GLConsumer.
109*38e8c45fSAndroid Build Coastguard Worker  */
110*38e8c45fSAndroid Build Coastguard Worker class Surface
111*38e8c45fSAndroid Build Coastguard Worker     : public ANativeObjectBase<ANativeWindow, Surface, RefBase>
112*38e8c45fSAndroid Build Coastguard Worker {
113*38e8c45fSAndroid Build Coastguard Worker public:
114*38e8c45fSAndroid Build Coastguard Worker     /*
115*38e8c45fSAndroid Build Coastguard Worker      * creates a Surface from the given IGraphicBufferProducer (which concrete
116*38e8c45fSAndroid Build Coastguard Worker      * implementation is a BufferQueue).
117*38e8c45fSAndroid Build Coastguard Worker      *
118*38e8c45fSAndroid Build Coastguard Worker      * Surface is mainly state-less while it's disconnected, it can be
119*38e8c45fSAndroid Build Coastguard Worker      * viewed as a glorified IGraphicBufferProducer holder. It's therefore
120*38e8c45fSAndroid Build Coastguard Worker      * safe to create other Surfaces from the same IGraphicBufferProducer.
121*38e8c45fSAndroid Build Coastguard Worker      *
122*38e8c45fSAndroid Build Coastguard Worker      * However, once a Surface is connected, it'll prevent other Surfaces
123*38e8c45fSAndroid Build Coastguard Worker      * referring to the same IGraphicBufferProducer to become connected and
124*38e8c45fSAndroid Build Coastguard Worker      * therefore prevent them to be used as actual producers of buffers.
125*38e8c45fSAndroid Build Coastguard Worker      *
126*38e8c45fSAndroid Build Coastguard Worker      * the controlledByApp flag indicates that this Surface (producer) is
127*38e8c45fSAndroid Build Coastguard Worker      * controlled by the application. This flag is used at connect time.
128*38e8c45fSAndroid Build Coastguard Worker      *
129*38e8c45fSAndroid Build Coastguard Worker      * Pass in the SurfaceControlHandle to store a weak reference to the layer
130*38e8c45fSAndroid Build Coastguard Worker      * that the Surface was created from. This handle can be used to create a
131*38e8c45fSAndroid Build Coastguard Worker      * child surface without using the IGBP to identify the layer. This is used
132*38e8c45fSAndroid Build Coastguard Worker      * for surfaces created by the BlastBufferQueue whose IGBP is created on the
133*38e8c45fSAndroid Build Coastguard Worker      * client and cannot be verified in SF.
134*38e8c45fSAndroid Build Coastguard Worker      */
135*38e8c45fSAndroid Build Coastguard Worker     explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false,
136*38e8c45fSAndroid Build Coastguard Worker                      const sp<IBinder>& surfaceControlHandle = nullptr);
137*38e8c45fSAndroid Build Coastguard Worker 
138*38e8c45fSAndroid Build Coastguard Worker     /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this
139*38e8c45fSAndroid Build Coastguard Worker      * Surface was created with. Usually it's an error to use the
140*38e8c45fSAndroid Build Coastguard Worker      * IGraphicBufferProducer while the Surface is connected.
141*38e8c45fSAndroid Build Coastguard Worker      */
142*38e8c45fSAndroid Build Coastguard Worker     sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
143*38e8c45fSAndroid Build Coastguard Worker 
144*38e8c45fSAndroid Build Coastguard Worker     sp<IBinder> getSurfaceControlHandle() const;
145*38e8c45fSAndroid Build Coastguard Worker 
146*38e8c45fSAndroid Build Coastguard Worker     /* convenience function to check that the given surface is non NULL as
147*38e8c45fSAndroid Build Coastguard Worker      * well as its IGraphicBufferProducer */
isValid(const sp<Surface> & surface)148*38e8c45fSAndroid Build Coastguard Worker     static bool isValid(const sp<Surface>& surface) {
149*38e8c45fSAndroid Build Coastguard Worker         return surface != nullptr && surface->getIGraphicBufferProducer() != nullptr;
150*38e8c45fSAndroid Build Coastguard Worker     }
151*38e8c45fSAndroid Build Coastguard Worker 
getIGraphicBufferProducer(ANativeWindow * window)152*38e8c45fSAndroid Build Coastguard Worker     static sp<IGraphicBufferProducer> getIGraphicBufferProducer(ANativeWindow* window) {
153*38e8c45fSAndroid Build Coastguard Worker         int val;
154*38e8c45fSAndroid Build Coastguard Worker         if (window->query(window, NATIVE_WINDOW_CONCRETE_TYPE, &val) >= 0 &&
155*38e8c45fSAndroid Build Coastguard Worker             val == NATIVE_WINDOW_SURFACE) {
156*38e8c45fSAndroid Build Coastguard Worker             return ((Surface*) window)->mGraphicBufferProducer;
157*38e8c45fSAndroid Build Coastguard Worker         }
158*38e8c45fSAndroid Build Coastguard Worker         return nullptr;
159*38e8c45fSAndroid Build Coastguard Worker     }
160*38e8c45fSAndroid Build Coastguard Worker 
getSurfaceControlHandle(ANativeWindow * window)161*38e8c45fSAndroid Build Coastguard Worker     static sp<IBinder> getSurfaceControlHandle(ANativeWindow* window) {
162*38e8c45fSAndroid Build Coastguard Worker         int val;
163*38e8c45fSAndroid Build Coastguard Worker         if (window->query(window, NATIVE_WINDOW_CONCRETE_TYPE, &val) >= 0 &&
164*38e8c45fSAndroid Build Coastguard Worker             val == NATIVE_WINDOW_SURFACE) {
165*38e8c45fSAndroid Build Coastguard Worker             return ((Surface*) window)->mSurfaceControlHandle;
166*38e8c45fSAndroid Build Coastguard Worker         }
167*38e8c45fSAndroid Build Coastguard Worker         return nullptr;
168*38e8c45fSAndroid Build Coastguard Worker     }
169*38e8c45fSAndroid Build Coastguard Worker 
170*38e8c45fSAndroid Build Coastguard Worker     /* Attaches a sideband buffer stream to the Surface's IGraphicBufferProducer.
171*38e8c45fSAndroid Build Coastguard Worker      *
172*38e8c45fSAndroid Build Coastguard Worker      * A sideband stream is a device-specific mechanism for passing buffers
173*38e8c45fSAndroid Build Coastguard Worker      * from the producer to the consumer without using dequeueBuffer/
174*38e8c45fSAndroid Build Coastguard Worker      * queueBuffer. If a sideband stream is present, the consumer can choose
175*38e8c45fSAndroid Build Coastguard Worker      * whether to acquire buffers from the sideband stream or from the queued
176*38e8c45fSAndroid Build Coastguard Worker      * buffers.
177*38e8c45fSAndroid Build Coastguard Worker      *
178*38e8c45fSAndroid Build Coastguard Worker      * Passing NULL or a different stream handle will detach the previous
179*38e8c45fSAndroid Build Coastguard Worker      * handle if any.
180*38e8c45fSAndroid Build Coastguard Worker      */
181*38e8c45fSAndroid Build Coastguard Worker     void setSidebandStream(const sp<NativeHandle>& stream);
182*38e8c45fSAndroid Build Coastguard Worker 
183*38e8c45fSAndroid Build Coastguard Worker     /* Allocates buffers based on the current dimensions/format.
184*38e8c45fSAndroid Build Coastguard Worker      *
185*38e8c45fSAndroid Build Coastguard Worker      * This function will allocate up to the maximum number of buffers
186*38e8c45fSAndroid Build Coastguard Worker      * permitted by the current BufferQueue configuration. It will use the
187*38e8c45fSAndroid Build Coastguard Worker      * default format and dimensions. This is most useful to avoid an allocation
188*38e8c45fSAndroid Build Coastguard Worker      * delay during dequeueBuffer. If there are already the maximum number of
189*38e8c45fSAndroid Build Coastguard Worker      * buffers allocated, this function has no effect.
190*38e8c45fSAndroid Build Coastguard Worker      */
191*38e8c45fSAndroid Build Coastguard Worker     virtual void allocateBuffers();
192*38e8c45fSAndroid Build Coastguard Worker 
193*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
194*38e8c45fSAndroid Build Coastguard Worker     // See IGraphicBufferProducer::allowAllocation
195*38e8c45fSAndroid Build Coastguard Worker     status_t allowAllocation(bool allowAllocation);
196*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
197*38e8c45fSAndroid Build Coastguard Worker 
198*38e8c45fSAndroid Build Coastguard Worker     /* Sets the generation number on the IGraphicBufferProducer and updates the
199*38e8c45fSAndroid Build Coastguard Worker      * generation number on any buffers attached to the Surface after this call.
200*38e8c45fSAndroid Build Coastguard Worker      * See IGBP::setGenerationNumber for more information. */
201*38e8c45fSAndroid Build Coastguard Worker     status_t setGenerationNumber(uint32_t generationNumber);
202*38e8c45fSAndroid Build Coastguard Worker 
203*38e8c45fSAndroid Build Coastguard Worker     // See IGraphicBufferProducer::getConsumerName
204*38e8c45fSAndroid Build Coastguard Worker     String8 getConsumerName() const;
205*38e8c45fSAndroid Build Coastguard Worker 
206*38e8c45fSAndroid Build Coastguard Worker     // See IGraphicBufferProducer::getNextFrameNumber
207*38e8c45fSAndroid Build Coastguard Worker     uint64_t getNextFrameNumber() const;
208*38e8c45fSAndroid Build Coastguard Worker 
209*38e8c45fSAndroid Build Coastguard Worker     /* Set the scaling mode to be used with a Surface.
210*38e8c45fSAndroid Build Coastguard Worker      * See NATIVE_WINDOW_SET_SCALING_MODE and its parameters
211*38e8c45fSAndroid Build Coastguard Worker      * in <system/window.h>. */
212*38e8c45fSAndroid Build Coastguard Worker     int setScalingMode(int mode);
213*38e8c45fSAndroid Build Coastguard Worker 
214*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersTimestamp(int64_t timestamp);
215*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersDataSpace(ui::Dataspace dataSpace);
216*38e8c45fSAndroid Build Coastguard Worker     virtual int setCrop(Rect const* rect);
217*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersTransform(uint32_t transform);
218*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersStickyTransform(uint32_t transform);
219*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersFormat(PixelFormat format);
220*38e8c45fSAndroid Build Coastguard Worker     virtual int setUsage(uint64_t reqUsage);
221*38e8c45fSAndroid Build Coastguard Worker 
222*38e8c45fSAndroid Build Coastguard Worker     // See IGraphicBufferProducer::setDequeueTimeout
223*38e8c45fSAndroid Build Coastguard Worker     status_t setDequeueTimeout(nsecs_t timeout);
224*38e8c45fSAndroid Build Coastguard Worker 
225*38e8c45fSAndroid Build Coastguard Worker     /*
226*38e8c45fSAndroid Build Coastguard Worker      * Wait for frame number to increase past lastFrame for at most
227*38e8c45fSAndroid Build Coastguard Worker      * timeoutNs. Useful for one thread to wait for another unknown
228*38e8c45fSAndroid Build Coastguard Worker      * thread to queue a buffer.
229*38e8c45fSAndroid Build Coastguard Worker      */
230*38e8c45fSAndroid Build Coastguard Worker     bool waitForNextFrame(uint64_t lastFrame, nsecs_t timeout);
231*38e8c45fSAndroid Build Coastguard Worker 
232*38e8c45fSAndroid Build Coastguard Worker     // See IGraphicBufferProducer::getLastQueuedBuffer
233*38e8c45fSAndroid Build Coastguard Worker     // See GLConsumer::getTransformMatrix for outTransformMatrix format
234*38e8c45fSAndroid Build Coastguard Worker     status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
235*38e8c45fSAndroid Build Coastguard Worker             sp<Fence>* outFence, float outTransformMatrix[16]);
236*38e8c45fSAndroid Build Coastguard Worker 
237*38e8c45fSAndroid Build Coastguard Worker     status_t getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration);
238*38e8c45fSAndroid Build Coastguard Worker 
239*38e8c45fSAndroid Build Coastguard Worker     /* Enables or disables frame timestamp tracking. It is disabled by default
240*38e8c45fSAndroid Build Coastguard Worker      * to avoid overhead during queue and dequeue for applications that don't
241*38e8c45fSAndroid Build Coastguard Worker      * need the feature. If disabled, calls to getFrameTimestamps will fail.
242*38e8c45fSAndroid Build Coastguard Worker      */
243*38e8c45fSAndroid Build Coastguard Worker     void enableFrameTimestamps(bool enable);
244*38e8c45fSAndroid Build Coastguard Worker 
245*38e8c45fSAndroid Build Coastguard Worker     status_t getCompositorTiming(
246*38e8c45fSAndroid Build Coastguard Worker             nsecs_t* compositeDeadline, nsecs_t* compositeInterval,
247*38e8c45fSAndroid Build Coastguard Worker             nsecs_t* compositeToPresentLatency);
248*38e8c45fSAndroid Build Coastguard Worker 
249*38e8c45fSAndroid Build Coastguard Worker     // See IGraphicBufferProducer::getFrameTimestamps
250*38e8c45fSAndroid Build Coastguard Worker     status_t getFrameTimestamps(uint64_t frameNumber,
251*38e8c45fSAndroid Build Coastguard Worker             nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime,
252*38e8c45fSAndroid Build Coastguard Worker             nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime,
253*38e8c45fSAndroid Build Coastguard Worker             nsecs_t* outLastRefreshStartTime, nsecs_t* outGlCompositionDoneTime,
254*38e8c45fSAndroid Build Coastguard Worker             nsecs_t* outDisplayPresentTime, nsecs_t* outDequeueReadyTime,
255*38e8c45fSAndroid Build Coastguard Worker             nsecs_t* outReleaseTime);
256*38e8c45fSAndroid Build Coastguard Worker 
257*38e8c45fSAndroid Build Coastguard Worker     status_t getWideColorSupport(bool* supported) __attribute__((__deprecated__));
258*38e8c45fSAndroid Build Coastguard Worker     status_t getHdrSupport(bool* supported) __attribute__((__deprecated__));
259*38e8c45fSAndroid Build Coastguard Worker 
260*38e8c45fSAndroid Build Coastguard Worker     status_t getUniqueId(uint64_t* outId) const;
261*38e8c45fSAndroid Build Coastguard Worker     status_t getConsumerUsage(uint64_t* outUsage) const;
262*38e8c45fSAndroid Build Coastguard Worker 
263*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setFrameRate(float frameRate, int8_t compatibility,
264*38e8c45fSAndroid Build Coastguard Worker                                   int8_t changeFrameRateStrategy);
265*38e8c45fSAndroid Build Coastguard Worker     virtual status_t setFrameTimelineInfo(uint64_t frameNumber, const FrameTimelineInfo& info);
266*38e8c45fSAndroid Build Coastguard Worker 
267*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE)
268*38e8c45fSAndroid Build Coastguard Worker     /**
269*38e8c45fSAndroid Build Coastguard Worker      * Set additional options to be passed when allocating a buffer. Only valid if IAllocator-V2
270*38e8c45fSAndroid Build Coastguard Worker      * or newer is available, otherwise will return INVALID_OPERATION. Only allowed to be called
271*38e8c45fSAndroid Build Coastguard Worker      * after connect and options are cleared when disconnect happens. Returns NO_INIT if not
272*38e8c45fSAndroid Build Coastguard Worker      * connected
273*38e8c45fSAndroid Build Coastguard Worker      */
274*38e8c45fSAndroid Build Coastguard Worker     status_t setAdditionalOptions(const std::vector<gui::AdditionalOptions>& options);
275*38e8c45fSAndroid Build Coastguard Worker #endif
276*38e8c45fSAndroid Build Coastguard Worker 
277*38e8c45fSAndroid Build Coastguard Worker protected:
278*38e8c45fSAndroid Build Coastguard Worker     virtual ~Surface();
279*38e8c45fSAndroid Build Coastguard Worker 
280*38e8c45fSAndroid Build Coastguard Worker     // Virtual for testing.
281*38e8c45fSAndroid Build Coastguard Worker     virtual sp<ISurfaceComposer> composerService() const;
282*38e8c45fSAndroid Build Coastguard Worker     virtual sp<gui::ISurfaceComposer> composerServiceAIDL() const;
283*38e8c45fSAndroid Build Coastguard Worker     virtual nsecs_t now() const;
284*38e8c45fSAndroid Build Coastguard Worker 
285*38e8c45fSAndroid Build Coastguard Worker private:
286*38e8c45fSAndroid Build Coastguard Worker     // can't be copied
287*38e8c45fSAndroid Build Coastguard Worker     Surface& operator = (const Surface& rhs);
288*38e8c45fSAndroid Build Coastguard Worker     Surface(const Surface& rhs);
289*38e8c45fSAndroid Build Coastguard Worker 
290*38e8c45fSAndroid Build Coastguard Worker     // ANativeWindow hooks
291*38e8c45fSAndroid Build Coastguard Worker     static int hook_cancelBuffer(ANativeWindow* window,
292*38e8c45fSAndroid Build Coastguard Worker             ANativeWindowBuffer* buffer, int fenceFd);
293*38e8c45fSAndroid Build Coastguard Worker     static int hook_dequeueBuffer(ANativeWindow* window,
294*38e8c45fSAndroid Build Coastguard Worker             ANativeWindowBuffer** buffer, int* fenceFd);
295*38e8c45fSAndroid Build Coastguard Worker     static int hook_perform(ANativeWindow* window, int operation, ...);
296*38e8c45fSAndroid Build Coastguard Worker     static int hook_query(const ANativeWindow* window, int what, int* value);
297*38e8c45fSAndroid Build Coastguard Worker     static int hook_queueBuffer(ANativeWindow* window,
298*38e8c45fSAndroid Build Coastguard Worker             ANativeWindowBuffer* buffer, int fenceFd);
299*38e8c45fSAndroid Build Coastguard Worker     static int hook_setSwapInterval(ANativeWindow* window, int interval);
300*38e8c45fSAndroid Build Coastguard Worker 
301*38e8c45fSAndroid Build Coastguard Worker     static int cancelBufferInternal(ANativeWindow* window, ANativeWindowBuffer* buffer,
302*38e8c45fSAndroid Build Coastguard Worker                                     int fenceFd);
303*38e8c45fSAndroid Build Coastguard Worker     static int dequeueBufferInternal(ANativeWindow* window, ANativeWindowBuffer** buffer,
304*38e8c45fSAndroid Build Coastguard Worker                                      int* fenceFd);
305*38e8c45fSAndroid Build Coastguard Worker     static int performInternal(ANativeWindow* window, int operation, va_list args);
306*38e8c45fSAndroid Build Coastguard Worker     static int queueBufferInternal(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);
307*38e8c45fSAndroid Build Coastguard Worker     static int queryInternal(const ANativeWindow* window, int what, int* value);
308*38e8c45fSAndroid Build Coastguard Worker 
309*38e8c45fSAndroid Build Coastguard Worker     static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
310*38e8c45fSAndroid Build Coastguard Worker             ANativeWindowBuffer* buffer);
311*38e8c45fSAndroid Build Coastguard Worker     static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
312*38e8c45fSAndroid Build Coastguard Worker             ANativeWindowBuffer** buffer);
313*38e8c45fSAndroid Build Coastguard Worker     static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
314*38e8c45fSAndroid Build Coastguard Worker             ANativeWindowBuffer* buffer);
315*38e8c45fSAndroid Build Coastguard Worker     static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
316*38e8c45fSAndroid Build Coastguard Worker             ANativeWindowBuffer* buffer);
317*38e8c45fSAndroid Build Coastguard Worker 
318*38e8c45fSAndroid Build Coastguard Worker     int dispatchConnect(va_list args);
319*38e8c45fSAndroid Build Coastguard Worker     int dispatchDisconnect(va_list args);
320*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBufferCount(va_list args);
321*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersGeometry(va_list args);
322*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersDimensions(va_list args);
323*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersUserDimensions(va_list args);
324*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersFormat(va_list args);
325*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetScalingMode(va_list args);
326*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersTransform(va_list args);
327*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersStickyTransform(va_list args);
328*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersTimestamp(va_list args);
329*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetCrop(va_list args);
330*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetUsage(va_list args);
331*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetUsage64(va_list args);
332*38e8c45fSAndroid Build Coastguard Worker     int dispatchLock(va_list args);
333*38e8c45fSAndroid Build Coastguard Worker     int dispatchUnlockAndPost(va_list args);
334*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetSidebandStream(va_list args);
335*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersDataSpace(va_list args);
336*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersSmpte2086Metadata(va_list args);
337*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersCta8613Metadata(va_list args);
338*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetBuffersHdr10PlusMetadata(va_list args);
339*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetSurfaceDamage(va_list args);
340*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetSharedBufferMode(va_list args);
341*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetAutoRefresh(va_list args);
342*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetDisplayRefreshCycleDuration(va_list args);
343*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetNextFrameId(va_list args);
344*38e8c45fSAndroid Build Coastguard Worker     int dispatchEnableFrameTimestamps(va_list args);
345*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetCompositorTiming(va_list args);
346*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetFrameTimestamps(va_list args);
347*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetWideColorSupport(va_list args);
348*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetHdrSupport(va_list args);
349*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetConsumerUsage64(va_list args);
350*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetAutoPrerotation(va_list args);
351*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetLastDequeueStartTime(va_list args);
352*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetDequeueTimeout(va_list args);
353*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetLastDequeueDuration(va_list args);
354*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetLastQueueDuration(va_list args);
355*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetFrameRate(va_list args);
356*38e8c45fSAndroid Build Coastguard Worker     int dispatchAddCancelInterceptor(va_list args);
357*38e8c45fSAndroid Build Coastguard Worker     int dispatchAddDequeueInterceptor(va_list args);
358*38e8c45fSAndroid Build Coastguard Worker     int dispatchAddPerformInterceptor(va_list args);
359*38e8c45fSAndroid Build Coastguard Worker     int dispatchAddQueueInterceptor(va_list args);
360*38e8c45fSAndroid Build Coastguard Worker     int dispatchAddQueryInterceptor(va_list args);
361*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetLastQueuedBuffer(va_list args);
362*38e8c45fSAndroid Build Coastguard Worker     int dispatchGetLastQueuedBuffer2(va_list args);
363*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetFrameTimelineInfo(va_list args);
364*38e8c45fSAndroid Build Coastguard Worker     int dispatchSetAdditionalOptions(va_list args);
365*38e8c45fSAndroid Build Coastguard Worker 
366*38e8c45fSAndroid Build Coastguard Worker     std::mutex mNameMutex;
367*38e8c45fSAndroid Build Coastguard Worker     std::string mName;
368*38e8c45fSAndroid Build Coastguard Worker     const char* getDebugName();
369*38e8c45fSAndroid Build Coastguard Worker 
370*38e8c45fSAndroid Build Coastguard Worker protected:
371*38e8c45fSAndroid Build Coastguard Worker     virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
372*38e8c45fSAndroid Build Coastguard Worker     virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
373*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
374*38e8c45fSAndroid Build Coastguard Worker     virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd,
375*38e8c45fSAndroid Build Coastguard Worker                             SurfaceQueueBufferOutput* surfaceOutput = nullptr);
376*38e8c45fSAndroid Build Coastguard Worker #else
377*38e8c45fSAndroid Build Coastguard Worker     virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
378*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
379*38e8c45fSAndroid Build Coastguard Worker     virtual int perform(int operation, va_list args);
380*38e8c45fSAndroid Build Coastguard Worker     virtual int setSwapInterval(int interval);
381*38e8c45fSAndroid Build Coastguard Worker 
382*38e8c45fSAndroid Build Coastguard Worker     virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
383*38e8c45fSAndroid Build Coastguard Worker 
384*38e8c45fSAndroid Build Coastguard Worker     virtual int connect(int api);
385*38e8c45fSAndroid Build Coastguard Worker     virtual int setBufferCount(int bufferCount);
386*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersUserDimensions(uint32_t width, uint32_t height);
387*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersSmpte2086Metadata(const android_smpte2086_metadata* metadata);
388*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersCta8613Metadata(const android_cta861_3_metadata* metadata);
389*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersHdr10PlusMetadata(const size_t size, const uint8_t* metadata);
390*38e8c45fSAndroid Build Coastguard Worker     virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects);
391*38e8c45fSAndroid Build Coastguard Worker 
392*38e8c45fSAndroid Build Coastguard Worker public:
393*38e8c45fSAndroid Build Coastguard Worker     virtual int disconnect(int api,
394*38e8c45fSAndroid Build Coastguard Worker             IGraphicBufferProducer::DisconnectMode mode =
395*38e8c45fSAndroid Build Coastguard Worker                     IGraphicBufferProducer::DisconnectMode::Api);
396*38e8c45fSAndroid Build Coastguard Worker 
397*38e8c45fSAndroid Build Coastguard Worker     virtual int setMaxDequeuedBufferCount(int maxDequeuedBuffers);
398*38e8c45fSAndroid Build Coastguard Worker     virtual int setAsyncMode(bool async);
399*38e8c45fSAndroid Build Coastguard Worker     virtual int setSharedBufferMode(bool sharedBufferMode);
400*38e8c45fSAndroid Build Coastguard Worker     virtual int setAutoRefresh(bool autoRefresh);
401*38e8c45fSAndroid Build Coastguard Worker     virtual int setAutoPrerotation(bool autoPrerotation);
402*38e8c45fSAndroid Build Coastguard Worker     virtual int setBuffersDimensions(uint32_t width, uint32_t height);
403*38e8c45fSAndroid Build Coastguard Worker     virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
404*38e8c45fSAndroid Build Coastguard Worker     virtual int unlockAndPost();
405*38e8c45fSAndroid Build Coastguard Worker     virtual int query(int what, int* value) const;
406*38e8c45fSAndroid Build Coastguard Worker 
407*38e8c45fSAndroid Build Coastguard Worker     // When reportBufferRemoval is true, clients must call getAndFlushRemovedBuffers to fetch
408*38e8c45fSAndroid Build Coastguard Worker     // GraphicBuffers removed from this surface after a dequeueBuffer, detachNextBuffer or
409*38e8c45fSAndroid Build Coastguard Worker     // attachBuffer call. This allows clients with their own buffer caches to free up buffers no
410*38e8c45fSAndroid Build Coastguard Worker     // longer in use by this surface.
411*38e8c45fSAndroid Build Coastguard Worker     virtual int connect(int api, const sp<SurfaceListener>& listener,
412*38e8c45fSAndroid Build Coastguard Worker                         bool reportBufferRemoval = false);
413*38e8c45fSAndroid Build Coastguard Worker     virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence);
414*38e8c45fSAndroid Build Coastguard Worker     virtual int attachBuffer(ANativeWindowBuffer*);
415*38e8c45fSAndroid Build Coastguard Worker 
416*38e8c45fSAndroid Build Coastguard Worker     virtual void destroy();
417*38e8c45fSAndroid Build Coastguard Worker 
418*38e8c45fSAndroid Build Coastguard Worker     // When client connects to Surface with reportBufferRemoval set to true, any buffers removed
419*38e8c45fSAndroid Build Coastguard Worker     // from this Surface will be collected and returned here. Once this method returns, these
420*38e8c45fSAndroid Build Coastguard Worker     // buffers will no longer be referenced by this Surface unless they are attached to this
421*38e8c45fSAndroid Build Coastguard Worker     // Surface later. The list of removed buffers will only be stored until the next dequeueBuffer,
422*38e8c45fSAndroid Build Coastguard Worker     // detachNextBuffer, or attachBuffer call.
423*38e8c45fSAndroid Build Coastguard Worker     status_t getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out);
424*38e8c45fSAndroid Build Coastguard Worker 
425*38e8c45fSAndroid Build Coastguard Worker     ui::Dataspace getBuffersDataSpace();
426*38e8c45fSAndroid Build Coastguard Worker 
427*38e8c45fSAndroid Build Coastguard Worker     static status_t attachAndQueueBufferWithDataspace(Surface* surface, sp<GraphicBuffer> buffer,
428*38e8c45fSAndroid Build Coastguard Worker                                                       ui::Dataspace dataspace);
429*38e8c45fSAndroid Build Coastguard Worker 
430*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
431*38e8c45fSAndroid Build Coastguard Worker     // Dequeues a buffer and its outFence, which must be signalled before the buffer can be used.
432*38e8c45fSAndroid Build Coastguard Worker     status_t dequeueBuffer(sp<GraphicBuffer>* buffer, sp<Fence>* outFence);
433*38e8c45fSAndroid Build Coastguard Worker 
434*38e8c45fSAndroid Build Coastguard Worker     // Queues a buffer, with an optional fd fence that captures pending work on the buffer. This
435*38e8c45fSAndroid Build Coastguard Worker     // buffer must have been returned by dequeueBuffer or associated with this Surface via an
436*38e8c45fSAndroid Build Coastguard Worker     // attachBuffer operation.
437*38e8c45fSAndroid Build Coastguard Worker     status_t queueBuffer(const sp<GraphicBuffer>& buffer, const sp<Fence>& fd = Fence::NO_FENCE,
438*38e8c45fSAndroid Build Coastguard Worker                          SurfaceQueueBufferOutput* output = nullptr);
439*38e8c45fSAndroid Build Coastguard Worker 
440*38e8c45fSAndroid Build Coastguard Worker     // Detaches this buffer, dissociating it from this Surface. This buffer must have been returned
441*38e8c45fSAndroid Build Coastguard Worker     // by queueBuffer or associated with this Surface via an attachBuffer operation.
442*38e8c45fSAndroid Build Coastguard Worker     status_t detachBuffer(const sp<GraphicBuffer>& buffer);
443*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
444*38e8c45fSAndroid Build Coastguard Worker 
445*38e8c45fSAndroid Build Coastguard Worker     // Batch version of dequeueBuffer, cancelBuffer and queueBuffer
446*38e8c45fSAndroid Build Coastguard Worker     // Note that these batched operations are not supported when shared buffer mode is being used.
447*38e8c45fSAndroid Build Coastguard Worker     struct BatchBuffer {
448*38e8c45fSAndroid Build Coastguard Worker         ANativeWindowBuffer* buffer = nullptr;
449*38e8c45fSAndroid Build Coastguard Worker         int fenceFd = -1;
450*38e8c45fSAndroid Build Coastguard Worker     };
451*38e8c45fSAndroid Build Coastguard Worker     virtual int dequeueBuffers(std::vector<BatchBuffer>* buffers);
452*38e8c45fSAndroid Build Coastguard Worker     virtual int cancelBuffers(const std::vector<BatchBuffer>& buffers);
453*38e8c45fSAndroid Build Coastguard Worker 
454*38e8c45fSAndroid Build Coastguard Worker     struct BatchQueuedBuffer {
455*38e8c45fSAndroid Build Coastguard Worker         ANativeWindowBuffer* buffer = nullptr;
456*38e8c45fSAndroid Build Coastguard Worker         int fenceFd = -1;
457*38e8c45fSAndroid Build Coastguard Worker         nsecs_t timestamp = NATIVE_WINDOW_TIMESTAMP_AUTO;
458*38e8c45fSAndroid Build Coastguard Worker     };
459*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
460*38e8c45fSAndroid Build Coastguard Worker     virtual int queueBuffers(const std::vector<BatchQueuedBuffer>& buffers,
461*38e8c45fSAndroid Build Coastguard Worker                              std::vector<SurfaceQueueBufferOutput>* queueBufferOutputs = nullptr);
462*38e8c45fSAndroid Build Coastguard Worker #else
463*38e8c45fSAndroid Build Coastguard Worker     virtual int queueBuffers(
464*38e8c45fSAndroid Build Coastguard Worker             const std::vector<BatchQueuedBuffer>& buffers);
465*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
466*38e8c45fSAndroid Build Coastguard Worker 
467*38e8c45fSAndroid Build Coastguard Worker protected:
468*38e8c45fSAndroid Build Coastguard Worker     enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
469*38e8c45fSAndroid Build Coastguard Worker     enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
470*38e8c45fSAndroid Build Coastguard Worker 
471*38e8c45fSAndroid Build Coastguard Worker     class ProducerListenerProxy : public BnProducerListener {
472*38e8c45fSAndroid Build Coastguard Worker     public:
ProducerListenerProxy(wp<Surface> parent,sp<SurfaceListener> listener)473*38e8c45fSAndroid Build Coastguard Worker         ProducerListenerProxy(wp<Surface> parent, sp<SurfaceListener> listener)
474*38e8c45fSAndroid Build Coastguard Worker                : mParent(parent), mSurfaceListener(listener) {}
~ProducerListenerProxy()475*38e8c45fSAndroid Build Coastguard Worker         virtual ~ProducerListenerProxy() {}
476*38e8c45fSAndroid Build Coastguard Worker 
onBufferReleased()477*38e8c45fSAndroid Build Coastguard Worker         virtual void onBufferReleased() {
478*38e8c45fSAndroid Build Coastguard Worker             mSurfaceListener->onBufferReleased();
479*38e8c45fSAndroid Build Coastguard Worker         }
480*38e8c45fSAndroid Build Coastguard Worker 
needsReleaseNotify()481*38e8c45fSAndroid Build Coastguard Worker         virtual bool needsReleaseNotify() {
482*38e8c45fSAndroid Build Coastguard Worker             return mSurfaceListener->needsReleaseNotify();
483*38e8c45fSAndroid Build Coastguard Worker         }
484*38e8c45fSAndroid Build Coastguard Worker 
onBufferDetached(int slot)485*38e8c45fSAndroid Build Coastguard Worker         virtual void onBufferDetached(int slot) { mSurfaceListener->onBufferDetached(slot); }
486*38e8c45fSAndroid Build Coastguard Worker 
487*38e8c45fSAndroid Build Coastguard Worker         virtual void onBuffersDiscarded(const std::vector<int32_t>& slots);
488*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_CONSUMER_ATTACH_CALLBACK)
onBufferAttached()489*38e8c45fSAndroid Build Coastguard Worker         virtual void onBufferAttached() {
490*38e8c45fSAndroid Build Coastguard Worker             mSurfaceListener->onBufferAttached();
491*38e8c45fSAndroid Build Coastguard Worker         }
492*38e8c45fSAndroid Build Coastguard Worker 
needsAttachNotify()493*38e8c45fSAndroid Build Coastguard Worker         virtual bool needsAttachNotify() {
494*38e8c45fSAndroid Build Coastguard Worker             return mSurfaceListener->needsAttachNotify();
495*38e8c45fSAndroid Build Coastguard Worker         }
496*38e8c45fSAndroid Build Coastguard Worker #endif
497*38e8c45fSAndroid Build Coastguard Worker     private:
498*38e8c45fSAndroid Build Coastguard Worker         wp<Surface> mParent;
499*38e8c45fSAndroid Build Coastguard Worker         sp<SurfaceListener> mSurfaceListener;
500*38e8c45fSAndroid Build Coastguard Worker     };
501*38e8c45fSAndroid Build Coastguard Worker 
502*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
503*38e8c45fSAndroid Build Coastguard Worker     class ProducerDeathListenerProxy : public IBinder::DeathRecipient {
504*38e8c45fSAndroid Build Coastguard Worker     public:
505*38e8c45fSAndroid Build Coastguard Worker         ProducerDeathListenerProxy(wp<SurfaceListener> surfaceListener);
506*38e8c45fSAndroid Build Coastguard Worker         ProducerDeathListenerProxy(ProducerDeathListenerProxy&) = delete;
507*38e8c45fSAndroid Build Coastguard Worker 
508*38e8c45fSAndroid Build Coastguard Worker         // IBinder::DeathRecipient
509*38e8c45fSAndroid Build Coastguard Worker         virtual void binderDied(const wp<IBinder>&) override;
510*38e8c45fSAndroid Build Coastguard Worker 
511*38e8c45fSAndroid Build Coastguard Worker     private:
512*38e8c45fSAndroid Build Coastguard Worker         wp<SurfaceListener> mSurfaceListener;
513*38e8c45fSAndroid Build Coastguard Worker     };
514*38e8c45fSAndroid Build Coastguard Worker     friend class ProducerDeathListenerProxy;
515*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
516*38e8c45fSAndroid Build Coastguard Worker 
517*38e8c45fSAndroid Build Coastguard Worker     void querySupportedTimestampsLocked() const;
518*38e8c45fSAndroid Build Coastguard Worker 
519*38e8c45fSAndroid Build Coastguard Worker     void freeAllBuffers();
520*38e8c45fSAndroid Build Coastguard Worker     int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
521*38e8c45fSAndroid Build Coastguard Worker 
522*38e8c45fSAndroid Build Coastguard Worker     void getDequeueBufferInputLocked(IGraphicBufferProducer::DequeueBufferInput* dequeueInput);
523*38e8c45fSAndroid Build Coastguard Worker 
524*38e8c45fSAndroid Build Coastguard Worker     void getQueueBufferInputLocked(android_native_buffer_t* buffer, int fenceFd, nsecs_t timestamp,
525*38e8c45fSAndroid Build Coastguard Worker             IGraphicBufferProducer::QueueBufferInput* out);
526*38e8c45fSAndroid Build Coastguard Worker 
527*38e8c45fSAndroid Build Coastguard Worker     // For easing in adoption of gralloc4 metadata by vendor components, as well as for supporting
528*38e8c45fSAndroid Build Coastguard Worker     // the public ANativeWindow api, allow setting relevant metadata when queueing a buffer through
529*38e8c45fSAndroid Build Coastguard Worker     // a native window
530*38e8c45fSAndroid Build Coastguard Worker     void applyGrallocMetadataLocked(
531*38e8c45fSAndroid Build Coastguard Worker             android_native_buffer_t* buffer,
532*38e8c45fSAndroid Build Coastguard Worker             const IGraphicBufferProducer::QueueBufferInput& queueBufferInput);
533*38e8c45fSAndroid Build Coastguard Worker 
534*38e8c45fSAndroid Build Coastguard Worker     void onBufferQueuedLocked(int slot, sp<Fence> fence,
535*38e8c45fSAndroid Build Coastguard Worker             const IGraphicBufferProducer::QueueBufferOutput& output);
536*38e8c45fSAndroid Build Coastguard Worker 
537*38e8c45fSAndroid Build Coastguard Worker     struct BufferSlot {
538*38e8c45fSAndroid Build Coastguard Worker         sp<GraphicBuffer> buffer;
539*38e8c45fSAndroid Build Coastguard Worker         Region dirtyRegion;
540*38e8c45fSAndroid Build Coastguard Worker     };
541*38e8c45fSAndroid Build Coastguard Worker 
542*38e8c45fSAndroid Build Coastguard Worker     // mSurfaceTexture is the interface to the surface texture server. All
543*38e8c45fSAndroid Build Coastguard Worker     // operations on the surface texture client ultimately translate into
544*38e8c45fSAndroid Build Coastguard Worker     // interactions with the server using this interface.
545*38e8c45fSAndroid Build Coastguard Worker     // TODO: rename to mBufferProducer
546*38e8c45fSAndroid Build Coastguard Worker     sp<IGraphicBufferProducer> mGraphicBufferProducer;
547*38e8c45fSAndroid Build Coastguard Worker 
548*38e8c45fSAndroid Build Coastguard Worker #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
549*38e8c45fSAndroid Build Coastguard Worker     // mSurfaceDeathListener gets registered as mGraphicBufferProducer's
550*38e8c45fSAndroid Build Coastguard Worker     // DeathRecipient when SurfaceListener::needsDeathNotify returns true and
551*38e8c45fSAndroid Build Coastguard Worker     // gets notified when it dies.
552*38e8c45fSAndroid Build Coastguard Worker     sp<ProducerDeathListenerProxy> mSurfaceDeathListener;
553*38e8c45fSAndroid Build Coastguard Worker #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
554*38e8c45fSAndroid Build Coastguard Worker 
555*38e8c45fSAndroid Build Coastguard Worker     // mSlots stores the buffers that have been allocated for each buffer slot.
556*38e8c45fSAndroid Build Coastguard Worker     // It is initialized to null pointers, and gets filled in with the result of
557*38e8c45fSAndroid Build Coastguard Worker     // IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
558*38e8c45fSAndroid Build Coastguard Worker     // slot that has not yet been used. The buffer allocated to a slot will also
559*38e8c45fSAndroid Build Coastguard Worker     // be replaced if the requested buffer usage or geometry differs from that
560*38e8c45fSAndroid Build Coastguard Worker     // of the buffer allocated to a slot.
561*38e8c45fSAndroid Build Coastguard Worker     BufferSlot mSlots[NUM_BUFFER_SLOTS];
562*38e8c45fSAndroid Build Coastguard Worker 
563*38e8c45fSAndroid Build Coastguard Worker     // mReqWidth is the buffer width that will be requested at the next dequeue
564*38e8c45fSAndroid Build Coastguard Worker     // operation. It is initialized to 1.
565*38e8c45fSAndroid Build Coastguard Worker     uint32_t mReqWidth;
566*38e8c45fSAndroid Build Coastguard Worker 
567*38e8c45fSAndroid Build Coastguard Worker     // mReqHeight is the buffer height that will be requested at the next
568*38e8c45fSAndroid Build Coastguard Worker     // dequeue operation. It is initialized to 1.
569*38e8c45fSAndroid Build Coastguard Worker     uint32_t mReqHeight;
570*38e8c45fSAndroid Build Coastguard Worker 
571*38e8c45fSAndroid Build Coastguard Worker     // mReqFormat is the buffer pixel format that will be requested at the next
572*38e8c45fSAndroid Build Coastguard Worker     // dequeue operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
573*38e8c45fSAndroid Build Coastguard Worker     PixelFormat mReqFormat;
574*38e8c45fSAndroid Build Coastguard Worker 
575*38e8c45fSAndroid Build Coastguard Worker     // mReqUsage is the set of buffer usage flags that will be requested
576*38e8c45fSAndroid Build Coastguard Worker     // at the next dequeue operation. It is initialized to 0.
577*38e8c45fSAndroid Build Coastguard Worker     uint64_t mReqUsage;
578*38e8c45fSAndroid Build Coastguard Worker 
579*38e8c45fSAndroid Build Coastguard Worker     // mTimestamp is the timestamp that will be used for the next buffer queue
580*38e8c45fSAndroid Build Coastguard Worker     // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
581*38e8c45fSAndroid Build Coastguard Worker     // a timestamp is auto-generated when queueBuffer is called.
582*38e8c45fSAndroid Build Coastguard Worker     int64_t mTimestamp;
583*38e8c45fSAndroid Build Coastguard Worker 
584*38e8c45fSAndroid Build Coastguard Worker     // mDataSpace is the buffer dataSpace that will be used for the next buffer
585*38e8c45fSAndroid Build Coastguard Worker     // queue operation. It defaults to Dataspace::UNKNOWN, which
586*38e8c45fSAndroid Build Coastguard Worker     // means that the buffer contains some type of color data.
587*38e8c45fSAndroid Build Coastguard Worker     ui::Dataspace mDataSpace;
588*38e8c45fSAndroid Build Coastguard Worker 
589*38e8c45fSAndroid Build Coastguard Worker     // mHdrMetadata is the HDR metadata that will be used for the next buffer
590*38e8c45fSAndroid Build Coastguard Worker     // queue operation.  There is no HDR metadata by default.
591*38e8c45fSAndroid Build Coastguard Worker     HdrMetadata mHdrMetadata;
592*38e8c45fSAndroid Build Coastguard Worker 
593*38e8c45fSAndroid Build Coastguard Worker     // mHdrMetadataIsSet is a bitfield to track which HDR metadata has been set.
594*38e8c45fSAndroid Build Coastguard Worker     // Prevent Surface from resetting HDR metadata that was set on a bufer when
595*38e8c45fSAndroid Build Coastguard Worker     // HDR metadata is not set on this Surface.
596*38e8c45fSAndroid Build Coastguard Worker     uint32_t mHdrMetadataIsSet{0};
597*38e8c45fSAndroid Build Coastguard Worker 
598*38e8c45fSAndroid Build Coastguard Worker     // mCrop is the crop rectangle that will be used for the next buffer
599*38e8c45fSAndroid Build Coastguard Worker     // that gets queued. It is set by calling setCrop.
600*38e8c45fSAndroid Build Coastguard Worker     Rect mCrop;
601*38e8c45fSAndroid Build Coastguard Worker 
602*38e8c45fSAndroid Build Coastguard Worker     // mScalingMode is the scaling mode that will be used for the next
603*38e8c45fSAndroid Build Coastguard Worker     // buffers that get queued. It is set by calling setScalingMode.
604*38e8c45fSAndroid Build Coastguard Worker     int mScalingMode;
605*38e8c45fSAndroid Build Coastguard Worker 
606*38e8c45fSAndroid Build Coastguard Worker     // mTransform is the transform identifier that will be used for the next
607*38e8c45fSAndroid Build Coastguard Worker     // buffer that gets queued. It is set by calling setTransform.
608*38e8c45fSAndroid Build Coastguard Worker     uint32_t mTransform;
609*38e8c45fSAndroid Build Coastguard Worker 
610*38e8c45fSAndroid Build Coastguard Worker     // mStickyTransform is a transform that is applied on top of mTransform
611*38e8c45fSAndroid Build Coastguard Worker     // in each buffer that is queued.  This is typically used to force the
612*38e8c45fSAndroid Build Coastguard Worker     // compositor to apply a transform, and will prevent the transform hint
613*38e8c45fSAndroid Build Coastguard Worker     // from being set by the compositor.
614*38e8c45fSAndroid Build Coastguard Worker     uint32_t mStickyTransform;
615*38e8c45fSAndroid Build Coastguard Worker 
616*38e8c45fSAndroid Build Coastguard Worker     // mDefaultWidth is default width of the buffers, regardless of the
617*38e8c45fSAndroid Build Coastguard Worker     // native_window_set_buffers_dimensions call.
618*38e8c45fSAndroid Build Coastguard Worker     uint32_t mDefaultWidth;
619*38e8c45fSAndroid Build Coastguard Worker 
620*38e8c45fSAndroid Build Coastguard Worker     // mDefaultHeight is default height of the buffers, regardless of the
621*38e8c45fSAndroid Build Coastguard Worker     // native_window_set_buffers_dimensions call.
622*38e8c45fSAndroid Build Coastguard Worker     uint32_t mDefaultHeight;
623*38e8c45fSAndroid Build Coastguard Worker 
624*38e8c45fSAndroid Build Coastguard Worker     // mUserWidth, if non-zero, is an application-specified override
625*38e8c45fSAndroid Build Coastguard Worker     // of mDefaultWidth.  This is lower priority than the width set by
626*38e8c45fSAndroid Build Coastguard Worker     // native_window_set_buffers_dimensions.
627*38e8c45fSAndroid Build Coastguard Worker     uint32_t mUserWidth;
628*38e8c45fSAndroid Build Coastguard Worker 
629*38e8c45fSAndroid Build Coastguard Worker     // mUserHeight, if non-zero, is an application-specified override
630*38e8c45fSAndroid Build Coastguard Worker     // of mDefaultHeight.  This is lower priority than the height set
631*38e8c45fSAndroid Build Coastguard Worker     // by native_window_set_buffers_dimensions.
632*38e8c45fSAndroid Build Coastguard Worker     uint32_t mUserHeight;
633*38e8c45fSAndroid Build Coastguard Worker 
634*38e8c45fSAndroid Build Coastguard Worker     // mTransformHint is the transform probably applied to buffers of this
635*38e8c45fSAndroid Build Coastguard Worker     // window. this is only a hint, actual transform may differ.
636*38e8c45fSAndroid Build Coastguard Worker     uint32_t mTransformHint;
getTransformHint()637*38e8c45fSAndroid Build Coastguard Worker     virtual uint32_t getTransformHint() const { return mTransformHint; }
638*38e8c45fSAndroid Build Coastguard Worker     bool transformToDisplayInverse() const;
639*38e8c45fSAndroid Build Coastguard Worker 
640*38e8c45fSAndroid Build Coastguard Worker     // mProducerControlledByApp whether this buffer producer is controlled
641*38e8c45fSAndroid Build Coastguard Worker     // by the application
642*38e8c45fSAndroid Build Coastguard Worker     bool mProducerControlledByApp;
643*38e8c45fSAndroid Build Coastguard Worker 
644*38e8c45fSAndroid Build Coastguard Worker     // mSwapIntervalZero set if we should drop buffers at queue() time to
645*38e8c45fSAndroid Build Coastguard Worker     // achieve an asynchronous swap interval
646*38e8c45fSAndroid Build Coastguard Worker     bool mSwapIntervalZero;
647*38e8c45fSAndroid Build Coastguard Worker 
648*38e8c45fSAndroid Build Coastguard Worker     // mConsumerRunningBehind whether the consumer is running more than
649*38e8c45fSAndroid Build Coastguard Worker     // one buffer behind the producer.
650*38e8c45fSAndroid Build Coastguard Worker     mutable bool mConsumerRunningBehind;
651*38e8c45fSAndroid Build Coastguard Worker 
652*38e8c45fSAndroid Build Coastguard Worker     // mMutex is the mutex used to prevent concurrent access to the member
653*38e8c45fSAndroid Build Coastguard Worker     // variables of Surface objects. It must be locked whenever the
654*38e8c45fSAndroid Build Coastguard Worker     // member variables are accessed.
655*38e8c45fSAndroid Build Coastguard Worker     mutable Mutex mMutex;
656*38e8c45fSAndroid Build Coastguard Worker 
657*38e8c45fSAndroid Build Coastguard Worker     // mInterceptorMutex is the mutex guarding interceptors.
658*38e8c45fSAndroid Build Coastguard Worker     mutable std::shared_mutex mInterceptorMutex;
659*38e8c45fSAndroid Build Coastguard Worker 
660*38e8c45fSAndroid Build Coastguard Worker     ANativeWindow_cancelBufferInterceptor mCancelInterceptor = nullptr;
661*38e8c45fSAndroid Build Coastguard Worker     void* mCancelInterceptorData = nullptr;
662*38e8c45fSAndroid Build Coastguard Worker     ANativeWindow_dequeueBufferInterceptor mDequeueInterceptor = nullptr;
663*38e8c45fSAndroid Build Coastguard Worker     void* mDequeueInterceptorData = nullptr;
664*38e8c45fSAndroid Build Coastguard Worker     ANativeWindow_performInterceptor mPerformInterceptor = nullptr;
665*38e8c45fSAndroid Build Coastguard Worker     void* mPerformInterceptorData = nullptr;
666*38e8c45fSAndroid Build Coastguard Worker     ANativeWindow_queueBufferInterceptor mQueueInterceptor = nullptr;
667*38e8c45fSAndroid Build Coastguard Worker     void* mQueueInterceptorData = nullptr;
668*38e8c45fSAndroid Build Coastguard Worker     ANativeWindow_queryInterceptor mQueryInterceptor = nullptr;
669*38e8c45fSAndroid Build Coastguard Worker     void* mQueryInterceptorData = nullptr;
670*38e8c45fSAndroid Build Coastguard Worker 
671*38e8c45fSAndroid Build Coastguard Worker     // must be used from the lock/unlock thread
672*38e8c45fSAndroid Build Coastguard Worker     sp<GraphicBuffer>           mLockedBuffer;
673*38e8c45fSAndroid Build Coastguard Worker     sp<GraphicBuffer>           mPostedBuffer;
674*38e8c45fSAndroid Build Coastguard Worker     bool                        mConnectedToCpu;
675*38e8c45fSAndroid Build Coastguard Worker 
676*38e8c45fSAndroid Build Coastguard Worker     // When a CPU producer is attached, this reflects the region that the
677*38e8c45fSAndroid Build Coastguard Worker     // producer wished to update as well as whether the Surface was able to copy
678*38e8c45fSAndroid Build Coastguard Worker     // the previous buffer back to allow a partial update.
679*38e8c45fSAndroid Build Coastguard Worker     //
680*38e8c45fSAndroid Build Coastguard Worker     // When a non-CPU producer is attached, this reflects the surface damage
681*38e8c45fSAndroid Build Coastguard Worker     // (the change since the previous frame) passed in by the producer.
682*38e8c45fSAndroid Build Coastguard Worker     Region mDirtyRegion;
683*38e8c45fSAndroid Build Coastguard Worker 
684*38e8c45fSAndroid Build Coastguard Worker     // mBufferAge tracks the age of the contents of the most recently dequeued
685*38e8c45fSAndroid Build Coastguard Worker     // buffer as the number of frames that have elapsed since it was last queued
686*38e8c45fSAndroid Build Coastguard Worker     uint64_t mBufferAge;
687*38e8c45fSAndroid Build Coastguard Worker 
688*38e8c45fSAndroid Build Coastguard Worker     // Stores the current generation number. See setGenerationNumber and
689*38e8c45fSAndroid Build Coastguard Worker     // IGraphicBufferProducer::setGenerationNumber for more information.
690*38e8c45fSAndroid Build Coastguard Worker     uint32_t mGenerationNumber;
691*38e8c45fSAndroid Build Coastguard Worker 
692*38e8c45fSAndroid Build Coastguard Worker     // Caches the values that have been passed to the producer.
693*38e8c45fSAndroid Build Coastguard Worker     bool mSharedBufferMode;
694*38e8c45fSAndroid Build Coastguard Worker     bool mAutoRefresh;
695*38e8c45fSAndroid Build Coastguard Worker     bool mAutoPrerotation;
696*38e8c45fSAndroid Build Coastguard Worker 
697*38e8c45fSAndroid Build Coastguard Worker     // If in shared buffer mode and auto refresh is enabled, store the shared
698*38e8c45fSAndroid Build Coastguard Worker     // buffer slot and return it for all calls to queue/dequeue without going
699*38e8c45fSAndroid Build Coastguard Worker     // over Binder.
700*38e8c45fSAndroid Build Coastguard Worker     int mSharedBufferSlot;
701*38e8c45fSAndroid Build Coastguard Worker 
702*38e8c45fSAndroid Build Coastguard Worker     // This is true if the shared buffer has already been queued/canceled. It's
703*38e8c45fSAndroid Build Coastguard Worker     // used to prevent a mismatch between the number of queue/dequeue calls.
704*38e8c45fSAndroid Build Coastguard Worker     bool mSharedBufferHasBeenQueued;
705*38e8c45fSAndroid Build Coastguard Worker 
706*38e8c45fSAndroid Build Coastguard Worker     // These are used to satisfy the NATIVE_WINDOW_LAST_*_DURATION queries
707*38e8c45fSAndroid Build Coastguard Worker     nsecs_t mLastDequeueDuration = 0;
708*38e8c45fSAndroid Build Coastguard Worker     nsecs_t mLastQueueDuration = 0;
709*38e8c45fSAndroid Build Coastguard Worker 
710*38e8c45fSAndroid Build Coastguard Worker     // Stores the time right before we call IGBP::dequeueBuffer
711*38e8c45fSAndroid Build Coastguard Worker     nsecs_t mLastDequeueStartTime = 0;
712*38e8c45fSAndroid Build Coastguard Worker 
713*38e8c45fSAndroid Build Coastguard Worker     Condition mQueueBufferCondition;
714*38e8c45fSAndroid Build Coastguard Worker 
715*38e8c45fSAndroid Build Coastguard Worker     uint64_t mNextFrameNumber = 1;
716*38e8c45fSAndroid Build Coastguard Worker     uint64_t mLastFrameNumber = 0;
717*38e8c45fSAndroid Build Coastguard Worker 
718*38e8c45fSAndroid Build Coastguard Worker     // Mutable because ANativeWindow::query needs this class const.
719*38e8c45fSAndroid Build Coastguard Worker     mutable bool mQueriedSupportedTimestamps;
720*38e8c45fSAndroid Build Coastguard Worker     mutable bool mFrameTimestampsSupportsPresent;
721*38e8c45fSAndroid Build Coastguard Worker 
722*38e8c45fSAndroid Build Coastguard Worker     // A cached copy of the FrameEventHistory maintained by the consumer.
723*38e8c45fSAndroid Build Coastguard Worker     bool mEnableFrameTimestamps = false;
724*38e8c45fSAndroid Build Coastguard Worker     std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory;
725*38e8c45fSAndroid Build Coastguard Worker 
726*38e8c45fSAndroid Build Coastguard Worker     // Reference to the SurfaceFlinger layer that was used to create this
727*38e8c45fSAndroid Build Coastguard Worker     // surface. This is only populated when the Surface is created from
728*38e8c45fSAndroid Build Coastguard Worker     // a BlastBufferQueue.
729*38e8c45fSAndroid Build Coastguard Worker     sp<IBinder> mSurfaceControlHandle;
730*38e8c45fSAndroid Build Coastguard Worker 
731*38e8c45fSAndroid Build Coastguard Worker     bool mReportRemovedBuffers = false;
732*38e8c45fSAndroid Build Coastguard Worker     std::vector<sp<GraphicBuffer>> mRemovedBuffers;
733*38e8c45fSAndroid Build Coastguard Worker     int mMaxBufferCount;
734*38e8c45fSAndroid Build Coastguard Worker 
735*38e8c45fSAndroid Build Coastguard Worker     sp<IProducerListener> mListenerProxy;
736*38e8c45fSAndroid Build Coastguard Worker 
737*38e8c45fSAndroid Build Coastguard Worker     // Get and flush the buffers of given slots, if the buffer in the slot
738*38e8c45fSAndroid Build Coastguard Worker     // is currently dequeued then it won't be flushed and won't be returned
739*38e8c45fSAndroid Build Coastguard Worker     // in outBuffers.
740*38e8c45fSAndroid Build Coastguard Worker     status_t getAndFlushBuffersFromSlots(const std::vector<int32_t>& slots,
741*38e8c45fSAndroid Build Coastguard Worker             std::vector<sp<GraphicBuffer>>* outBuffers);
742*38e8c45fSAndroid Build Coastguard Worker 
743*38e8c45fSAndroid Build Coastguard Worker     // Buffers that are successfully dequeued/attached and handed to clients
744*38e8c45fSAndroid Build Coastguard Worker     std::unordered_set<int> mDequeuedSlots;
745*38e8c45fSAndroid Build Coastguard Worker };
746*38e8c45fSAndroid Build Coastguard Worker 
747*38e8c45fSAndroid Build Coastguard Worker } // namespace android
748*38e8c45fSAndroid Build Coastguard Worker 
749*38e8c45fSAndroid Build Coastguard Worker #endif  // ANDROID_GUI_SURFACE_H
750