blob: 641d62cd4decf7d82b7f0fce46a0aeab1cf1f051 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
Mathias Agopiane3c697f2013-02-14 17:11:02 -08002 * Copyright (C) 2010 The Android Open Source Project
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08003 *
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
Mathias Agopian90ac7992012-02-25 18:48:35 -080017#ifndef ANDROID_GUI_SURFACE_H
18#define ANDROID_GUI_SURFACE_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
Mathias Agopian2b5dd402017-02-07 17:36:19 -080020#include <gui/BufferQueueDefs.h>
Courtney Goeltzenleuchter9bad0d72017-12-19 12:34:34 -070021#include <gui/HdrMetadata.h>
22#include <gui/IGraphicBufferProducer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023
Mathias Agopiane3c697f2013-02-14 17:11:02 -080024#include <ui/ANativeObjectBase.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <ui/Region.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070026
Mathias Agopian2b5dd402017-02-07 17:36:19 -080027#include <utils/Condition.h>
28#include <utils/Mutex.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080029#include <utils/RefBase.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080030
Mathias Agopian6a3c05b2017-04-27 20:06:55 -070031#include <system/window.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080032
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033namespace android {
34
Brian Anderson3da8d272016-07-28 16:20:47 -070035class ISurfaceComposer;
36
Mathias Agopiane3c697f2013-02-14 17:11:02 -080037/*
38 * An implementation of ANativeWindow that feeds graphics buffers into a
39 * BufferQueue.
40 *
41 * This is typically used by programs that want to render frames through
42 * some means (maybe OpenGL, a software renderer, or a hardware decoder)
43 * and have the frames they create forwarded to SurfaceFlinger for
44 * compositing. For example, a video decoder could render a frame and call
45 * eglSwapBuffers(), which invokes ANativeWindow callbacks defined by
46 * Surface. Surface then forwards the buffers through Binder IPC
47 * to the BufferQueue's producer interface, providing the new frame to a
48 * consumer such as GLConsumer.
49 */
50class Surface
51 : public ANativeObjectBase<ANativeWindow, Surface, RefBase>
Mathias Agopian62185b72009-04-16 16:19:50 -070052{
53public:
Mathias Agopian62185b72009-04-16 16:19:50 -070054
Mathias Agopiancf0b8c82013-02-19 18:24:40 -080055 /*
56 * creates a Surface from the given IGraphicBufferProducer (which concrete
57 * implementation is a BufferQueue).
58 *
59 * Surface is mainly state-less while it's disconnected, it can be
60 * viewed as a glorified IGraphicBufferProducer holder. It's therefore
61 * safe to create other Surfaces from the same IGraphicBufferProducer.
62 *
63 * However, once a Surface is connected, it'll prevent other Surfaces
64 * referring to the same IGraphicBufferProducer to become connected and
65 * therefore prevent them to be used as actual producers of buffers.
Mathias Agopian595264f2013-07-16 22:56:09 -070066 *
67 * the controlledByApp flag indicates that this Surface (producer) is
68 * controlled by the application. This flag is used at connect time.
Mathias Agopiancf0b8c82013-02-19 18:24:40 -080069 */
Brian Anderson3da8d272016-07-28 16:20:47 -070070 explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer,
71 bool controlledByApp = false);
Mathias Agopian01b76682009-04-16 20:04:08 -070072
Mathias Agopiancf0b8c82013-02-19 18:24:40 -080073 /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this
74 * Surface was created with. Usually it's an error to use the
75 * IGraphicBufferProducer while the Surface is connected.
76 */
Mathias Agopiane3c697f2013-02-14 17:11:02 -080077 sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
78
Mathias Agopiancf0b8c82013-02-19 18:24:40 -080079 /* convenience function to check that the given surface is non NULL as
80 * well as its IGraphicBufferProducer */
Mathias Agopianc4905eb2013-02-15 16:34:04 -080081 static bool isValid(const sp<Surface>& surface) {
Mathias Agopianf25c5082013-02-15 14:59:09 -080082 return surface != NULL && surface->getIGraphicBufferProducer() != NULL;
83 }
84
Jesse Hall399184a2014-03-03 15:42:54 -080085 /* Attaches a sideband buffer stream to the Surface's IGraphicBufferProducer.
86 *
87 * A sideband stream is a device-specific mechanism for passing buffers
88 * from the producer to the consumer without using dequeueBuffer/
89 * queueBuffer. If a sideband stream is present, the consumer can choose
90 * whether to acquire buffers from the sideband stream or from the queued
91 * buffers.
92 *
93 * Passing NULL or a different stream handle will detach the previous
94 * handle if any.
95 */
96 void setSidebandStream(const sp<NativeHandle>& stream);
97
Dan Stoza29a3e902014-06-20 13:13:57 -070098 /* Allocates buffers based on the current dimensions/format.
99 *
100 * This function will allocate up to the maximum number of buffers
101 * permitted by the current BufferQueue configuration. It will use the
102 * default format and dimensions. This is most useful to avoid an allocation
103 * delay during dequeueBuffer. If there are already the maximum number of
104 * buffers allocated, this function has no effect.
105 */
106 void allocateBuffers();
107
Dan Stoza812ed062015-06-02 15:45:22 -0700108 /* Sets the generation number on the IGraphicBufferProducer and updates the
109 * generation number on any buffers attached to the Surface after this call.
110 * See IGBP::setGenerationNumber for more information. */
111 status_t setGenerationNumber(uint32_t generationNumber);
112
Dan Stozac6f30bd2015-06-08 09:32:50 -0700113 // See IGraphicBufferProducer::getConsumerName
114 String8 getConsumerName() const;
115
Dan Stoza7dde5992015-05-22 09:51:44 -0700116 // See IGraphicBufferProducer::getNextFrameNumber
117 uint64_t getNextFrameNumber() const;
118
Robert Carrc2e77882015-12-16 18:14:03 -0800119 /* Set the scaling mode to be used with a Surface.
120 * See NATIVE_WINDOW_SET_SCALING_MODE and its parameters
121 * in <system/window.h>. */
122 int setScalingMode(int mode);
123
Dan Stoza127fc632015-06-30 13:43:32 -0700124 // See IGraphicBufferProducer::setDequeueTimeout
125 status_t setDequeueTimeout(nsecs_t timeout);
126
Robert Carr9f31e292016-04-11 11:15:32 -0700127 /*
128 * Wait for frame number to increase past lastFrame for at most
129 * timeoutNs. Useful for one thread to wait for another unknown
130 * thread to queue a buffer.
131 */
132 bool waitForNextFrame(uint64_t lastFrame, nsecs_t timeout);
133
Dan Stoza50101d02016-04-07 16:53:23 -0700134 // See IGraphicBufferProducer::getLastQueuedBuffer
John Reck1a61da52016-04-28 13:18:15 -0700135 // See GLConsumer::getTransformMatrix for outTransformMatrix format
Dan Stoza50101d02016-04-07 16:53:23 -0700136 status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
John Reck1a61da52016-04-28 13:18:15 -0700137 sp<Fence>* outFence, float outTransformMatrix[16]);
Dan Stoza50101d02016-04-07 16:53:23 -0700138
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800139 status_t getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration);
140
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700141 /* Enables or disables frame timestamp tracking. It is disabled by default
142 * to avoid overhead during queue and dequeue for applications that don't
143 * need the feature. If disabled, calls to getFrameTimestamps will fail.
144 */
145 void enableFrameTimestamps(bool enable);
146
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800147 status_t getCompositorTiming(
148 nsecs_t* compositeDeadline, nsecs_t* compositeInterval,
149 nsecs_t* compositeToPresentLatency);
150
Pablo Ceballosce796e72016-02-04 19:10:51 -0800151 // See IGraphicBufferProducer::getFrameTimestamps
Brian Anderson069b3652016-07-22 10:32:47 -0700152 status_t getFrameTimestamps(uint64_t frameNumber,
Brian Andersondbd0ea82016-07-22 09:38:59 -0700153 nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700154 nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime,
155 nsecs_t* outLastRefreshStartTime, nsecs_t* outGlCompositionDoneTime,
Brian Anderson4e606e32017-03-16 15:34:57 -0700156 nsecs_t* outDisplayPresentTime, nsecs_t* outDequeueReadyTime,
157 nsecs_t* outReleaseTime);
Ian Elliott62c48c92017-01-20 13:13:20 -0700158
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700159 status_t getWideColorSupport(bool* supported);
Courtney Goeltzenleuchterc5b97c52017-02-26 14:47:13 -0700160 status_t getHdrSupport(bool* supported);
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700161
Pablo Ceballos8e3e92b2016-06-27 17:56:53 -0700162 status_t getUniqueId(uint64_t* outId) const;
Chia-I Wue2786ea2017-08-07 10:36:08 -0700163 status_t getConsumerUsage(uint64_t* outUsage) const;
Pablo Ceballos8e3e92b2016-06-27 17:56:53 -0700164
Dan Stoza932f0082017-05-31 13:50:16 -0700165 // Returns the CLOCK_MONOTONIC start time of the last dequeueBuffer call
166 nsecs_t getLastDequeueStartTime() const;
167
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800168protected:
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800169 virtual ~Surface();
Mathias Agopian01b76682009-04-16 20:04:08 -0700170
Brian Anderson3da8d272016-07-28 16:20:47 -0700171 // Virtual for testing.
172 virtual sp<ISurfaceComposer> composerService() const;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800173 virtual nsecs_t now() const;
Brian Anderson3da8d272016-07-28 16:20:47 -0700174
Mathias Agopian62185b72009-04-16 16:19:50 -0700175private:
Mathias Agopian01b76682009-04-16 20:04:08 -0700176 // can't be copied
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800177 Surface& operator = (const Surface& rhs);
178 Surface(const Surface& rhs);
Mathias Agopian01b76682009-04-16 20:04:08 -0700179
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800180 // ANativeWindow hooks
181 static int hook_cancelBuffer(ANativeWindow* window,
182 ANativeWindowBuffer* buffer, int fenceFd);
183 static int hook_dequeueBuffer(ANativeWindow* window,
184 ANativeWindowBuffer** buffer, int* fenceFd);
185 static int hook_perform(ANativeWindow* window, int operation, ...);
186 static int hook_query(const ANativeWindow* window, int what, int* value);
187 static int hook_queueBuffer(ANativeWindow* window,
188 ANativeWindowBuffer* buffer, int fenceFd);
189 static int hook_setSwapInterval(ANativeWindow* window, int interval);
Mathias Agopian01b76682009-04-16 20:04:08 -0700190
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800191 static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
192 ANativeWindowBuffer* buffer);
193 static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
194 ANativeWindowBuffer** buffer);
195 static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
196 ANativeWindowBuffer* buffer);
197 static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
198 ANativeWindowBuffer* buffer);
Mathias Agopian62185b72009-04-16 16:19:50 -0700199
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800200 int dispatchConnect(va_list args);
201 int dispatchDisconnect(va_list args);
202 int dispatchSetBufferCount(va_list args);
203 int dispatchSetBuffersGeometry(va_list args);
204 int dispatchSetBuffersDimensions(va_list args);
205 int dispatchSetBuffersUserDimensions(va_list args);
206 int dispatchSetBuffersFormat(va_list args);
207 int dispatchSetScalingMode(va_list args);
208 int dispatchSetBuffersTransform(va_list args);
Ruben Brunk1681d952014-06-27 15:51:55 -0700209 int dispatchSetBuffersStickyTransform(va_list args);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800210 int dispatchSetBuffersTimestamp(va_list args);
211 int dispatchSetCrop(va_list args);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800212 int dispatchSetUsage(va_list args);
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700213 int dispatchSetUsage64(va_list args);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800214 int dispatchLock(va_list args);
215 int dispatchUnlockAndPost(va_list args);
Rachad7cb0d392014-07-29 17:53:53 -0700216 int dispatchSetSidebandStream(va_list args);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800217 int dispatchSetBuffersDataSpace(va_list args);
Courtney Goeltzenleuchter9bad0d72017-12-19 12:34:34 -0700218 int dispatchSetBuffersSmpte2086Metadata(va_list args);
219 int dispatchSetBuffersCta8613Metadata(va_list args);
Dan Stoza5065a552015-03-17 16:23:42 -0700220 int dispatchSetSurfaceDamage(va_list args);
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700221 int dispatchSetSharedBufferMode(va_list args);
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800222 int dispatchSetAutoRefresh(va_list args);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800223 int dispatchGetDisplayRefreshCycleDuration(va_list args);
Brian Anderson1049d1d2016-12-16 17:25:57 -0800224 int dispatchGetNextFrameId(va_list args);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700225 int dispatchEnableFrameTimestamps(va_list args);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800226 int dispatchGetCompositorTiming(va_list args);
Pablo Ceballosce796e72016-02-04 19:10:51 -0800227 int dispatchGetFrameTimestamps(va_list args);
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700228 int dispatchGetWideColorSupport(va_list args);
Courtney Goeltzenleuchterc5b97c52017-02-26 14:47:13 -0700229 int dispatchGetHdrSupport(va_list args);
Chia-I Wue2786ea2017-08-07 10:36:08 -0700230 int dispatchGetConsumerUsage64(va_list args);
Mathias Agopian01b76682009-04-16 20:04:08 -0700231
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800232protected:
233 virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
234 virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
235 virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
236 virtual int perform(int operation, va_list args);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800237 virtual int setSwapInterval(int interval);
Mathias Agopian62185b72009-04-16 16:19:50 -0700238
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800239 virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
240
241 virtual int connect(int api);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800242 virtual int setBufferCount(int bufferCount);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800243 virtual int setBuffersUserDimensions(uint32_t width, uint32_t height);
244 virtual int setBuffersFormat(PixelFormat format);
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800245 virtual int setBuffersTransform(uint32_t transform);
246 virtual int setBuffersStickyTransform(uint32_t transform);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800247 virtual int setBuffersTimestamp(int64_t timestamp);
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800248 virtual int setBuffersDataSpace(android_dataspace dataSpace);
Courtney Goeltzenleuchter9bad0d72017-12-19 12:34:34 -0700249 virtual int setBuffersSmpte2086Metadata(const android_smpte2086_metadata* metadata);
250 virtual int setBuffersCta8613Metadata(const android_cta861_3_metadata* metadata);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800251 virtual int setCrop(Rect const* rect);
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700252 virtual int setUsage(uint64_t reqUsage);
Dan Stoza5065a552015-03-17 16:23:42 -0700253 virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800254
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800255public:
Robert Carr97b9c862016-09-08 13:54:35 -0700256 virtual int disconnect(int api,
257 IGraphicBufferProducer::DisconnectMode mode =
258 IGraphicBufferProducer::DisconnectMode::Api);
259
Pablo Ceballos19e3e062015-08-19 16:16:06 -0700260 virtual int setMaxDequeuedBufferCount(int maxDequeuedBuffers);
261 virtual int setAsyncMode(bool async);
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700262 virtual int setSharedBufferMode(bool sharedBufferMode);
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800263 virtual int setAutoRefresh(bool autoRefresh);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700264 virtual int setBuffersDimensions(uint32_t width, uint32_t height);
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800265 virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
266 virtual int unlockAndPost();
Dan Stoza70ccba52016-07-01 14:00:40 -0700267 virtual int query(int what, int* value) const;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800268
Dan Stoza231832e2015-03-11 11:55:01 -0700269 virtual int connect(int api, const sp<IProducerListener>& listener);
Yin-Chia Yehe572fd72017-03-28 19:07:39 -0700270
271 // When reportBufferRemoval is true, clients must call getAndFlushRemovedBuffers to fetch
272 // GraphicBuffers removed from this surface after a dequeueBuffer, detachNextBuffer or
273 // attachBuffer call. This allows clients with their own buffer caches to free up buffers no
274 // longer in use by this surface.
275 virtual int connect(
276 int api, const sp<IProducerListener>& listener,
277 bool reportBufferRemoval);
Dan Stozad9c49712015-04-27 11:06:01 -0700278 virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer,
Dan Stoza231832e2015-03-11 11:55:01 -0700279 sp<Fence>* outFence);
280 virtual int attachBuffer(ANativeWindowBuffer*);
281
Yin-Chia Yehe572fd72017-03-28 19:07:39 -0700282 // When client connects to Surface with reportBufferRemoval set to true, any buffers removed
283 // from this Surface will be collected and returned here. Once this method returns, these
284 // buffers will no longer be referenced by this Surface unless they are attached to this
285 // Surface later. The list of removed buffers will only be stored until the next dequeueBuffer,
286 // detachNextBuffer, or attachBuffer call.
287 status_t getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out);
288
Courtney Goeltzenleuchter152279d2017-08-14 18:18:30 -0600289 android_dataspace_t getBuffersDataSpace();
290
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000291 static status_t attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffer);
292
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800293protected:
Mathias Agopian2b5dd402017-02-07 17:36:19 -0800294 enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS };
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800295 enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
296
Brian Anderson069b3652016-07-22 10:32:47 -0700297 void querySupportedTimestampsLocked() const;
298
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800299 void freeAllBuffers();
300 int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
301
302 struct BufferSlot {
303 sp<GraphicBuffer> buffer;
304 Region dirtyRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800305 };
306
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800307 // mSurfaceTexture is the interface to the surface texture server. All
308 // operations on the surface texture client ultimately translate into
309 // interactions with the server using this interface.
310 // TODO: rename to mBufferProducer
311 sp<IGraphicBufferProducer> mGraphicBufferProducer;
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700312
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800313 // mSlots stores the buffers that have been allocated for each buffer slot.
314 // It is initialized to null pointers, and gets filled in with the result of
315 // IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
316 // slot that has not yet been used. The buffer allocated to a slot will also
317 // be replaced if the requested buffer usage or geometry differs from that
318 // of the buffer allocated to a slot.
319 BufferSlot mSlots[NUM_BUFFER_SLOTS];
Ted Bonkenburgbd050ab2011-07-15 15:10:10 -0700320
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800321 // mReqWidth is the buffer width that will be requested at the next dequeue
322 // operation. It is initialized to 1.
323 uint32_t mReqWidth;
Mathias Agopianba5972f2009-08-14 18:52:17 -0700324
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800325 // mReqHeight is the buffer height that will be requested at the next
326 // dequeue operation. It is initialized to 1.
327 uint32_t mReqHeight;
Mathias Agopian01b76682009-04-16 20:04:08 -0700328
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800329 // mReqFormat is the buffer pixel format that will be requested at the next
330 // deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800331 PixelFormat mReqFormat;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800332
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800333 // mReqUsage is the set of buffer usage flags that will be requested
334 // at the next deuque operation. It is initialized to 0.
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700335 uint64_t mReqUsage;
Mathias Agopianb2965332010-04-27 16:41:19 -0700336
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800337 // mTimestamp is the timestamp that will be used for the next buffer queue
338 // operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
339 // a timestamp is auto-generated when queueBuffer is called.
340 int64_t mTimestamp;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800341
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800342 // mDataSpace is the buffer dataSpace that will be used for the next buffer
343 // queue operation. It defaults to HAL_DATASPACE_UNKNOWN, which
344 // means that the buffer contains some type of color data.
345 android_dataspace mDataSpace;
346
Courtney Goeltzenleuchter9bad0d72017-12-19 12:34:34 -0700347 // mHdrMetadata is the HDR metadata that will be used for the next buffer
348 // queue operation. There is no HDR metadata by default.
349 HdrMetadata mHdrMetadata;
350
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800351 // mCrop is the crop rectangle that will be used for the next buffer
352 // that gets queued. It is set by calling setCrop.
353 Rect mCrop;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800354
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800355 // mScalingMode is the scaling mode that will be used for the next
356 // buffers that get queued. It is set by calling setScalingMode.
357 int mScalingMode;
Mathias Agopianb2965332010-04-27 16:41:19 -0700358
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800359 // mTransform is the transform identifier that will be used for the next
360 // buffer that gets queued. It is set by calling setTransform.
361 uint32_t mTransform;
Mathias Agopianb2965332010-04-27 16:41:19 -0700362
Ruben Brunk1681d952014-06-27 15:51:55 -0700363 // mStickyTransform is a transform that is applied on top of mTransform
364 // in each buffer that is queued. This is typically used to force the
365 // compositor to apply a transform, and will prevent the transform hint
366 // from being set by the compositor.
367 uint32_t mStickyTransform;
368
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800369 // mDefaultWidth is default width of the buffers, regardless of the
370 // native_window_set_buffers_dimensions call.
371 uint32_t mDefaultWidth;
Jamie Gennisaca4e222010-07-15 17:29:15 -0700372
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800373 // mDefaultHeight is default height of the buffers, regardless of the
374 // native_window_set_buffers_dimensions call.
375 uint32_t mDefaultHeight;
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700376
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800377 // mUserWidth, if non-zero, is an application-specified override
378 // of mDefaultWidth. This is lower priority than the width set by
379 // native_window_set_buffers_dimensions.
380 uint32_t mUserWidth;
Mathias Agopianba5972f2009-08-14 18:52:17 -0700381
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800382 // mUserHeight, if non-zero, is an application-specified override
383 // of mDefaultHeight. This is lower priority than the height set
384 // by native_window_set_buffers_dimensions.
385 uint32_t mUserHeight;
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800386
387 // mTransformHint is the transform probably applied to buffers of this
388 // window. this is only a hint, actual transform may differ.
389 uint32_t mTransformHint;
390
Mathias Agopian595264f2013-07-16 22:56:09 -0700391 // mProducerControlledByApp whether this buffer producer is controlled
392 // by the application
393 bool mProducerControlledByApp;
394
Mathias Agopian7cdd7862013-07-18 22:10:56 -0700395 // mSwapIntervalZero set if we should drop buffers at queue() time to
396 // achieve an asynchronous swap interval
397 bool mSwapIntervalZero;
398
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800399 // mConsumerRunningBehind whether the consumer is running more than
400 // one buffer behind the producer.
401 mutable bool mConsumerRunningBehind;
402
403 // mMutex is the mutex used to prevent concurrent access to the member
404 // variables of Surface objects. It must be locked whenever the
405 // member variables are accessed.
406 mutable Mutex mMutex;
407
408 // must be used from the lock/unlock thread
409 sp<GraphicBuffer> mLockedBuffer;
410 sp<GraphicBuffer> mPostedBuffer;
411 bool mConnectedToCpu;
412
Dan Stozac62acbd2015-04-21 16:42:49 -0700413 // When a CPU producer is attached, this reflects the region that the
414 // producer wished to update as well as whether the Surface was able to copy
415 // the previous buffer back to allow a partial update.
Dan Stoza5065a552015-03-17 16:23:42 -0700416 //
Dan Stozac62acbd2015-04-21 16:42:49 -0700417 // When a non-CPU producer is attached, this reflects the surface damage
418 // (the change since the previous frame) passed in by the producer.
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800419 Region mDirtyRegion;
Dan Stoza812ed062015-06-02 15:45:22 -0700420
Ian Elliotta2eb34c2017-07-18 11:05:49 -0600421 // mBufferAge tracks the age of the contents of the most recently dequeued
422 // buffer as the number of frames that have elapsed since it was last queued
423 uint64_t mBufferAge;
424
Dan Stoza812ed062015-06-02 15:45:22 -0700425 // Stores the current generation number. See setGenerationNumber and
426 // IGraphicBufferProducer::setGenerationNumber for more information.
427 uint32_t mGenerationNumber;
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800428
429 // Caches the values that have been passed to the producer.
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700430 bool mSharedBufferMode;
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800431 bool mAutoRefresh;
432
Pablo Ceballos3559fbf2016-03-17 15:50:23 -0700433 // If in shared buffer mode and auto refresh is enabled, store the shared
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800434 // buffer slot and return it for all calls to queue/dequeue without going
435 // over Binder.
436 int mSharedBufferSlot;
437
438 // This is true if the shared buffer has already been queued/canceled. It's
439 // used to prevent a mismatch between the number of queue/dequeue calls.
440 bool mSharedBufferHasBeenQueued;
Robert Carr9f31e292016-04-11 11:15:32 -0700441
Dan Stoza70ccba52016-07-01 14:00:40 -0700442 // These are used to satisfy the NATIVE_WINDOW_LAST_*_DURATION queries
443 nsecs_t mLastDequeueDuration = 0;
444 nsecs_t mLastQueueDuration = 0;
445
Dan Stoza932f0082017-05-31 13:50:16 -0700446 // Stores the time right before we call IGBP::dequeueBuffer
447 nsecs_t mLastDequeueStartTime = 0;
448
Robert Carr9f31e292016-04-11 11:15:32 -0700449 Condition mQueueBufferCondition;
Pablo Ceballosbc8c1922016-07-01 14:15:41 -0700450
Brian Anderson50143b32016-09-30 14:01:24 -0700451 uint64_t mNextFrameNumber = 1;
452 uint64_t mLastFrameNumber = 0;
Brian Anderson069b3652016-07-22 10:32:47 -0700453
Brian Anderson6b376712017-04-04 10:51:39 -0700454 // Mutable because ANativeWindow::query needs this class const.
455 mutable bool mQueriedSupportedTimestamps;
456 mutable bool mFrameTimestampsSupportsPresent;
457
Brian Anderson3890c392016-07-25 12:48:08 -0700458 // A cached copy of the FrameEventHistory maintained by the consumer.
Brian Anderson7c3ba8a2016-07-25 12:48:08 -0700459 bool mEnableFrameTimestamps = false;
Brian Anderson3da8d272016-07-28 16:20:47 -0700460 std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory;
Yin-Chia Yehe572fd72017-03-28 19:07:39 -0700461
462 bool mReportRemovedBuffers = false;
463 std::vector<sp<GraphicBuffer>> mRemovedBuffers;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800464};
465
Mathias Agopian05debe12017-02-08 17:04:18 -0800466} // namespace android
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800467
Mathias Agopiane3c697f2013-02-14 17:11:02 -0800468#endif // ANDROID_GUI_SURFACE_H