| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_GUI_SURFACE_H | 
|  | 18 | #define ANDROID_GUI_SURFACE_H | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 |  | 
| Mathias Agopian | 2b5dd40 | 2017-02-07 17:36:19 -0800 | [diff] [blame] | 20 | #include <gui/BufferQueueDefs.h> | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 21 | #include <gui/HdrMetadata.h> | 
|  | 22 | #include <gui/IGraphicBufferProducer.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 24 | #include <ui/ANativeObjectBase.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <ui/Region.h> | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 26 |  | 
| Mathias Agopian | 2b5dd40 | 2017-02-07 17:36:19 -0800 | [diff] [blame] | 27 | #include <utils/Condition.h> | 
|  | 28 | #include <utils/Mutex.h> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 29 | #include <utils/RefBase.h> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 30 |  | 
| Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 31 | #include <system/window.h> | 
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 32 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | namespace android { | 
|  | 34 |  | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 35 | class ISurfaceComposer; | 
|  | 36 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 37 | /* | 
|  | 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 | */ | 
|  | 50 | class Surface | 
|  | 51 | : public ANativeObjectBase<ANativeWindow, Surface, RefBase> | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 52 | { | 
|  | 53 | public: | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 54 |  | 
| Mathias Agopian | cf0b8c8 | 2013-02-19 18:24:40 -0800 | [diff] [blame] | 55 | /* | 
|  | 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 Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 66 | * | 
|  | 67 | * the controlledByApp flag indicates that this Surface (producer) is | 
|  | 68 | * controlled by the application. This flag is used at connect time. | 
| Mathias Agopian | cf0b8c8 | 2013-02-19 18:24:40 -0800 | [diff] [blame] | 69 | */ | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 70 | explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, | 
|  | 71 | bool controlledByApp = false); | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 72 |  | 
| Mathias Agopian | cf0b8c8 | 2013-02-19 18:24:40 -0800 | [diff] [blame] | 73 | /* 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 Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 77 | sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; | 
|  | 78 |  | 
| Mathias Agopian | cf0b8c8 | 2013-02-19 18:24:40 -0800 | [diff] [blame] | 79 | /* convenience function to check that the given surface is non NULL as | 
|  | 80 | * well as its IGraphicBufferProducer */ | 
| Mathias Agopian | c4905eb | 2013-02-15 16:34:04 -0800 | [diff] [blame] | 81 | static bool isValid(const sp<Surface>& surface) { | 
| Mathias Agopian | f25c508 | 2013-02-15 14:59:09 -0800 | [diff] [blame] | 82 | return surface != NULL && surface->getIGraphicBufferProducer() != NULL; | 
|  | 83 | } | 
|  | 84 |  | 
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 85 | /* 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 Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 98 | /* 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 Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 108 | /* 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 Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 113 | // See IGraphicBufferProducer::getConsumerName | 
|  | 114 | String8 getConsumerName() const; | 
|  | 115 |  | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 116 | // See IGraphicBufferProducer::getNextFrameNumber | 
|  | 117 | uint64_t getNextFrameNumber() const; | 
|  | 118 |  | 
| Robert Carr | c2e7788 | 2015-12-16 18:14:03 -0800 | [diff] [blame] | 119 | /* 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 Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 124 | // See IGraphicBufferProducer::setDequeueTimeout | 
|  | 125 | status_t setDequeueTimeout(nsecs_t timeout); | 
|  | 126 |  | 
| Robert Carr | 9f31e29 | 2016-04-11 11:15:32 -0700 | [diff] [blame] | 127 | /* | 
|  | 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 Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 134 | // See IGraphicBufferProducer::getLastQueuedBuffer | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 135 | // See GLConsumer::getTransformMatrix for outTransformMatrix format | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 136 | status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, | 
| John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 137 | sp<Fence>* outFence, float outTransformMatrix[16]); | 
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 138 |  | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 139 | status_t getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration); | 
|  | 140 |  | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 141 | /* 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 Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 147 | status_t getCompositorTiming( | 
|  | 148 | nsecs_t* compositeDeadline, nsecs_t* compositeInterval, | 
|  | 149 | nsecs_t* compositeToPresentLatency); | 
|  | 150 |  | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 151 | // See IGraphicBufferProducer::getFrameTimestamps | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 152 | status_t getFrameTimestamps(uint64_t frameNumber, | 
| Brian Anderson | dbd0ea8 | 2016-07-22 09:38:59 -0700 | [diff] [blame] | 153 | nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime, | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 154 | nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime, | 
|  | 155 | nsecs_t* outLastRefreshStartTime, nsecs_t* outGlCompositionDoneTime, | 
| Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 156 | nsecs_t* outDisplayPresentTime, nsecs_t* outDequeueReadyTime, | 
|  | 157 | nsecs_t* outReleaseTime); | 
| Ian Elliott | 62c48c9 | 2017-01-20 13:13:20 -0700 | [diff] [blame] | 158 |  | 
| Courtney Goeltzenleuchter | 1eb1b27 | 2017-02-02 16:51:06 -0700 | [diff] [blame] | 159 | status_t getWideColorSupport(bool* supported); | 
| Courtney Goeltzenleuchter | c5b97c5 | 2017-02-26 14:47:13 -0700 | [diff] [blame] | 160 | status_t getHdrSupport(bool* supported); | 
| Courtney Goeltzenleuchter | 1eb1b27 | 2017-02-02 16:51:06 -0700 | [diff] [blame] | 161 |  | 
| Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 162 | status_t getUniqueId(uint64_t* outId) const; | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 163 | status_t getConsumerUsage(uint64_t* outUsage) const; | 
| Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 164 |  | 
| Dan Stoza | 932f008 | 2017-05-31 13:50:16 -0700 | [diff] [blame] | 165 | // Returns the CLOCK_MONOTONIC start time of the last dequeueBuffer call | 
|  | 166 | nsecs_t getLastDequeueStartTime() const; | 
|  | 167 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 168 | protected: | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 169 | virtual ~Surface(); | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 170 |  | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 171 | // Virtual for testing. | 
|  | 172 | virtual sp<ISurfaceComposer> composerService() const; | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 173 | virtual nsecs_t now() const; | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 174 |  | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 175 | private: | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 176 | // can't be copied | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 177 | Surface& operator = (const Surface& rhs); | 
|  | 178 | Surface(const Surface& rhs); | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 179 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 180 | // 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 Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 190 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 191 | 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 Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 199 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 200 | 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 Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 209 | int dispatchSetBuffersStickyTransform(va_list args); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 210 | int dispatchSetBuffersTimestamp(va_list args); | 
|  | 211 | int dispatchSetCrop(va_list args); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 212 | int dispatchSetUsage(va_list args); | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 213 | int dispatchSetUsage64(va_list args); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 214 | int dispatchLock(va_list args); | 
|  | 215 | int dispatchUnlockAndPost(va_list args); | 
| Rachad | 7cb0d39 | 2014-07-29 17:53:53 -0700 | [diff] [blame] | 216 | int dispatchSetSidebandStream(va_list args); | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 217 | int dispatchSetBuffersDataSpace(va_list args); | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 218 | int dispatchSetBuffersSmpte2086Metadata(va_list args); | 
|  | 219 | int dispatchSetBuffersCta8613Metadata(va_list args); | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 220 | int dispatchSetSurfaceDamage(va_list args); | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 221 | int dispatchSetSharedBufferMode(va_list args); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 222 | int dispatchSetAutoRefresh(va_list args); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 223 | int dispatchGetDisplayRefreshCycleDuration(va_list args); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 224 | int dispatchGetNextFrameId(va_list args); | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 225 | int dispatchEnableFrameTimestamps(va_list args); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 226 | int dispatchGetCompositorTiming(va_list args); | 
| Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 227 | int dispatchGetFrameTimestamps(va_list args); | 
| Courtney Goeltzenleuchter | 1eb1b27 | 2017-02-02 16:51:06 -0700 | [diff] [blame] | 228 | int dispatchGetWideColorSupport(va_list args); | 
| Courtney Goeltzenleuchter | c5b97c5 | 2017-02-26 14:47:13 -0700 | [diff] [blame] | 229 | int dispatchGetHdrSupport(va_list args); | 
| Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 230 | int dispatchGetConsumerUsage64(va_list args); | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 231 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 232 | protected: | 
|  | 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 Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 237 | virtual int setSwapInterval(int interval); | 
| Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 238 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 239 | virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer); | 
|  | 240 |  | 
|  | 241 | virtual int connect(int api); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 242 | virtual int setBufferCount(int bufferCount); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 243 | virtual int setBuffersUserDimensions(uint32_t width, uint32_t height); | 
|  | 244 | virtual int setBuffersFormat(PixelFormat format); | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 245 | virtual int setBuffersTransform(uint32_t transform); | 
|  | 246 | virtual int setBuffersStickyTransform(uint32_t transform); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 247 | virtual int setBuffersTimestamp(int64_t timestamp); | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 248 | virtual int setBuffersDataSpace(android_dataspace dataSpace); | 
| Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 249 | virtual int setBuffersSmpte2086Metadata(const android_smpte2086_metadata* metadata); | 
|  | 250 | virtual int setBuffersCta8613Metadata(const android_cta861_3_metadata* metadata); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 251 | virtual int setCrop(Rect const* rect); | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 252 | virtual int setUsage(uint64_t reqUsage); | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 253 | virtual void setSurfaceDamage(android_native_rect_t* rects, size_t numRects); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 254 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | public: | 
| Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 256 | virtual int disconnect(int api, | 
|  | 257 | IGraphicBufferProducer::DisconnectMode mode = | 
|  | 258 | IGraphicBufferProducer::DisconnectMode::Api); | 
|  | 259 |  | 
| Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 260 | virtual int setMaxDequeuedBufferCount(int maxDequeuedBuffers); | 
|  | 261 | virtual int setAsyncMode(bool async); | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 262 | virtual int setSharedBufferMode(bool sharedBufferMode); | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 263 | virtual int setAutoRefresh(bool autoRefresh); | 
| Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 264 | virtual int setBuffersDimensions(uint32_t width, uint32_t height); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 265 | virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds); | 
|  | 266 | virtual int unlockAndPost(); | 
| Dan Stoza | 70ccba5 | 2016-07-01 14:00:40 -0700 | [diff] [blame] | 267 | virtual int query(int what, int* value) const; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 268 |  | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 269 | virtual int connect(int api, const sp<IProducerListener>& listener); | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 270 |  | 
|  | 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 Stoza | d9c4971 | 2015-04-27 11:06:01 -0700 | [diff] [blame] | 278 | virtual int detachNextBuffer(sp<GraphicBuffer>* outBuffer, | 
| Dan Stoza | 231832e | 2015-03-11 11:55:01 -0700 | [diff] [blame] | 279 | sp<Fence>* outFence); | 
|  | 280 | virtual int attachBuffer(ANativeWindowBuffer*); | 
|  | 281 |  | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 282 | // 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 Goeltzenleuchter | 152279d | 2017-08-14 18:18:30 -0600 | [diff] [blame] | 289 | android_dataspace_t getBuffersDataSpace(); | 
|  | 290 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 291 | static status_t attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffer); | 
|  | 292 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 293 | protected: | 
| Mathias Agopian | 2b5dd40 | 2017-02-07 17:36:19 -0800 | [diff] [blame] | 294 | enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS }; | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 295 | enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; | 
|  | 296 |  | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 297 | void querySupportedTimestampsLocked() const; | 
|  | 298 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 299 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | }; | 
|  | 306 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 307 | // 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 Bonkenburg | bd050ab | 2011-07-15 15:10:10 -0700 | [diff] [blame] | 312 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 313 | // 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 Bonkenburg | bd050ab | 2011-07-15 15:10:10 -0700 | [diff] [blame] | 320 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 321 | // 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 Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 324 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 325 | // 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 Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 328 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 329 | // 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 Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 331 | PixelFormat mReqFormat; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 333 | // mReqUsage is the set of buffer usage flags that will be requested | 
|  | 334 | // at the next deuque operation. It is initialized to 0. | 
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 335 | uint64_t mReqUsage; | 
| Mathias Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 336 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 337 | // 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 |  | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 342 | // 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 Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 347 | // 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 Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 351 | // 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 355 | // 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 Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 358 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 359 | // 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 Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 362 |  | 
| Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 363 | // 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 Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 369 | // mDefaultWidth is default width of the buffers, regardless of the | 
|  | 370 | // native_window_set_buffers_dimensions call. | 
|  | 371 | uint32_t mDefaultWidth; | 
| Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 372 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 373 | // mDefaultHeight is default height of the buffers, regardless of the | 
|  | 374 | // native_window_set_buffers_dimensions call. | 
|  | 375 | uint32_t mDefaultHeight; | 
| Mathias Agopian | 8f9dbf9 | 2011-07-13 17:39:11 -0700 | [diff] [blame] | 376 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 377 | // 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 Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 381 |  | 
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 382 | // 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 Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 386 |  | 
|  | 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 Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 391 | // mProducerControlledByApp whether this buffer producer is controlled | 
|  | 392 | // by the application | 
|  | 393 | bool mProducerControlledByApp; | 
|  | 394 |  | 
| Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 395 | // mSwapIntervalZero set if we should drop buffers at queue() time to | 
|  | 396 | // achieve an asynchronous swap interval | 
|  | 397 | bool mSwapIntervalZero; | 
|  | 398 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 399 | // 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 Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame] | 413 | // 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 Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 416 | // | 
| Dan Stoza | c62acbd | 2015-04-21 16:42:49 -0700 | [diff] [blame] | 417 | // 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 Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 419 | Region mDirtyRegion; | 
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 420 |  | 
| Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 421 | // 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 Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 425 | // Stores the current generation number. See setGenerationNumber and | 
|  | 426 | // IGraphicBufferProducer::setGenerationNumber for more information. | 
|  | 427 | uint32_t mGenerationNumber; | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 428 |  | 
|  | 429 | // Caches the values that have been passed to the producer. | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 430 | bool mSharedBufferMode; | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 431 | bool mAutoRefresh; | 
|  | 432 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 433 | // If in shared buffer mode and auto refresh is enabled, store the shared | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 434 | // 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 Carr | 9f31e29 | 2016-04-11 11:15:32 -0700 | [diff] [blame] | 441 |  | 
| Dan Stoza | 70ccba5 | 2016-07-01 14:00:40 -0700 | [diff] [blame] | 442 | // These are used to satisfy the NATIVE_WINDOW_LAST_*_DURATION queries | 
|  | 443 | nsecs_t mLastDequeueDuration = 0; | 
|  | 444 | nsecs_t mLastQueueDuration = 0; | 
|  | 445 |  | 
| Dan Stoza | 932f008 | 2017-05-31 13:50:16 -0700 | [diff] [blame] | 446 | // Stores the time right before we call IGBP::dequeueBuffer | 
|  | 447 | nsecs_t mLastDequeueStartTime = 0; | 
|  | 448 |  | 
| Robert Carr | 9f31e29 | 2016-04-11 11:15:32 -0700 | [diff] [blame] | 449 | Condition mQueueBufferCondition; | 
| Pablo Ceballos | bc8c192 | 2016-07-01 14:15:41 -0700 | [diff] [blame] | 450 |  | 
| Brian Anderson | 50143b3 | 2016-09-30 14:01:24 -0700 | [diff] [blame] | 451 | uint64_t mNextFrameNumber = 1; | 
|  | 452 | uint64_t mLastFrameNumber = 0; | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 453 |  | 
| Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 454 | // Mutable because ANativeWindow::query needs this class const. | 
|  | 455 | mutable bool mQueriedSupportedTimestamps; | 
|  | 456 | mutable bool mFrameTimestampsSupportsPresent; | 
|  | 457 |  | 
| Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 458 | // A cached copy of the FrameEventHistory maintained by the consumer. | 
| Brian Anderson | 7c3ba8a | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 459 | bool mEnableFrameTimestamps = false; | 
| Brian Anderson | 3da8d27 | 2016-07-28 16:20:47 -0700 | [diff] [blame] | 460 | std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory; | 
| Yin-Chia Yeh | e572fd7 | 2017-03-28 19:07:39 -0700 | [diff] [blame] | 461 |  | 
|  | 462 | bool mReportRemovedBuffers = false; | 
|  | 463 | std::vector<sp<GraphicBuffer>> mRemovedBuffers; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | }; | 
|  | 465 |  | 
| Mathias Agopian | 05debe1 | 2017-02-08 17:04:18 -0800 | [diff] [blame] | 466 | } // namespace android | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 |  | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 468 | #endif  // ANDROID_GUI_SURFACE_H |