| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_GUI_BLAST_BUFFER_QUEUE_H |
| 18 | #define ANDROID_GUI_BLAST_BUFFER_QUEUE_H |
| 19 | |
| 20 | #include <gui/IGraphicBufferProducer.h> |
| 21 | #include <gui/BufferItemConsumer.h> |
| 22 | #include <gui/BufferItem.h> |
| 23 | #include <gui/SurfaceComposerClient.h> |
| 24 | |
| 25 | #include <utils/Condition.h> |
| 26 | #include <utils/Mutex.h> |
| 27 | #include <utils/RefBase.h> |
| 28 | |
| 29 | #include <system/window.h> |
| Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 30 | #include <thread> |
| Jorim Jaggi | a3fe67b | 2020-12-01 00:24:33 +0100 | [diff] [blame] | 31 | #include <queue> |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
| Hongguang Chen | 621ec58 | 2021-02-16 15:42:35 -0800 | [diff] [blame] | 35 | class BLASTBufferQueue; |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 36 | class BufferItemConsumer; |
| 37 | |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 38 | class BLASTBufferItemConsumer : public BufferItemConsumer { |
| 39 | public: |
| 40 | BLASTBufferItemConsumer(const sp<IGraphicBufferConsumer>& consumer, uint64_t consumerUsage, |
| Ady Abraham | dbca135 | 2021-12-15 11:58:56 -0800 | [diff] [blame] | 41 | int bufferCount, bool controlledByApp, wp<BLASTBufferQueue> bbq) |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 42 | : BufferItemConsumer(consumer, consumerUsage, bufferCount, controlledByApp), |
| Ady Abraham | dbca135 | 2021-12-15 11:58:56 -0800 | [diff] [blame] | 43 | mBLASTBufferQueue(std::move(bbq)), |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 44 | mCurrentlyConnected(false), |
| Ady Abraham | dbca135 | 2021-12-15 11:58:56 -0800 | [diff] [blame] | 45 | mPreviouslyConnected(false) {} |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 46 | |
| 47 | void onDisconnect() override; |
| 48 | void addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, |
| Hongguang Chen | 621ec58 | 2021-02-16 15:42:35 -0800 | [diff] [blame] | 49 | FrameEventHistoryDelta* outDelta) override REQUIRES(mMutex); |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 50 | void updateFrameTimestamps(uint64_t frameNumber, nsecs_t refreshStartTime, |
| 51 | const sp<Fence>& gpuCompositionDoneFence, |
| 52 | const sp<Fence>& presentFence, const sp<Fence>& prevReleaseFence, |
| 53 | CompositorTiming compositorTiming, nsecs_t latchTime, |
| Hongguang Chen | 621ec58 | 2021-02-16 15:42:35 -0800 | [diff] [blame] | 54 | nsecs_t dequeueReadyTime) REQUIRES(mMutex); |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 55 | void getConnectionEvents(uint64_t frameNumber, bool* needsDisconnect); |
| Hongguang Chen | 621ec58 | 2021-02-16 15:42:35 -0800 | [diff] [blame] | 56 | |
| 57 | protected: |
| 58 | void onSidebandStreamChanged() override REQUIRES(mMutex); |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 59 | |
| 60 | private: |
| Ady Abraham | dbca135 | 2021-12-15 11:58:56 -0800 | [diff] [blame] | 61 | const wp<BLASTBufferQueue> mBLASTBufferQueue; |
| 62 | |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 63 | uint64_t mCurrentFrameNumber = 0; |
| 64 | |
| Hongguang Chen | 621ec58 | 2021-02-16 15:42:35 -0800 | [diff] [blame] | 65 | Mutex mMutex; |
| 66 | ConsumerFrameEventHistory mFrameEventHistory GUARDED_BY(mMutex); |
| 67 | std::queue<uint64_t> mDisconnectEvents GUARDED_BY(mMutex); |
| 68 | bool mCurrentlyConnected GUARDED_BY(mMutex); |
| 69 | bool mPreviouslyConnected GUARDED_BY(mMutex); |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 72 | class BLASTBufferQueue |
| 73 | : public ConsumerBase::FrameAvailableListener, public BufferItemConsumer::BufferFreedListener |
| 74 | { |
| 75 | public: |
| Vishnu Nair | d2aaab1 | 2022-02-10 14:49:09 -0800 | [diff] [blame] | 76 | BLASTBufferQueue(const std::string& name, bool updateDestinationFrame = true); |
| Vishnu Nair | dab9409 | 2020-09-29 16:09:04 -0700 | [diff] [blame] | 77 | BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width, |
| Vishnu Nair | debd1cb | 2021-03-16 10:06:01 -0700 | [diff] [blame] | 78 | int height, int32_t format); |
| Robert Carr | cedef05 | 2020-04-22 15:58:23 -0700 | [diff] [blame] | 79 | |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 80 | sp<IGraphicBufferProducer> getIGraphicBufferProducer() const { |
| 81 | return mProducer; |
| 82 | } |
| Vishnu Nair | 992496b | 2020-10-22 17:27:21 -0700 | [diff] [blame] | 83 | sp<Surface> getSurface(bool includeSurfaceControlHandle); |
| Vishnu Nair | 1e8bf10 | 2021-12-28 14:36:59 -0800 | [diff] [blame] | 84 | bool isSameSurfaceControl(const sp<SurfaceControl>& surfaceControl) const; |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 85 | |
| 86 | void onBufferFreed(const wp<GraphicBuffer>&/* graphicBuffer*/) override { /* TODO */ } |
| Vishnu Nair | aef1de9 | 2020-10-22 12:15:53 -0700 | [diff] [blame] | 87 | void onFrameReplaced(const BufferItem& item) override; |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 88 | void onFrameAvailable(const BufferItem& item) override; |
| Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 89 | void onFrameDequeued(const uint64_t) override; |
| 90 | void onFrameCancelled(const uint64_t) override; |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 91 | |
| chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 92 | void transactionCommittedCallback(nsecs_t latchTime, const sp<Fence>& presentFence, |
| 93 | const std::vector<SurfaceControlStats>& stats); |
| 94 | virtual void transactionCallback(nsecs_t latchTime, const sp<Fence>& presentFence, |
| 95 | const std::vector<SurfaceControlStats>& stats); |
| Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 96 | void releaseBufferCallback(const ReleaseCallbackId& id, const sp<Fence>& releaseFence, |
| chaviw | 69058fb | 2021-09-27 09:37:30 -0500 | [diff] [blame] | 97 | std::optional<uint32_t> currentMaxAcquiredBufferCount); |
| Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 98 | void syncNextTransaction(std::function<void(SurfaceComposerClient::Transaction*)> callback, |
| 99 | bool acquireSingleBuffer = true); |
| 100 | void stopContinuousSyncTransaction(); |
| Vishnu Nair | c4a40c1 | 2020-12-23 09:14:32 -0800 | [diff] [blame] | 101 | void mergeWithNextTransaction(SurfaceComposerClient::Transaction* t, uint64_t frameNumber); |
| chaviw | 6a19527 | 2021-09-03 16:14:25 -0500 | [diff] [blame] | 102 | void applyPendingTransactions(uint64_t frameNumber); |
| chaviw | d84085a | 2022-02-08 11:07:04 -0600 | [diff] [blame] | 103 | SurfaceComposerClient::Transaction* gatherPendingTransactions(uint64_t frameNumber); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 104 | |
| Vishnu Nair | d2aaab1 | 2022-02-10 14:49:09 -0800 | [diff] [blame] | 105 | void update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height, int32_t format); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 106 | |
| Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 107 | status_t setFrameRate(float frameRate, int8_t compatibility, bool shouldBeSeamless); |
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 108 | status_t setFrameTimelineInfo(const FrameTimelineInfo& info); |
| Robert Carr | 9c006e0 | 2020-10-14 13:41:57 -0700 | [diff] [blame] | 109 | |
| Hongguang Chen | 621ec58 | 2021-02-16 15:42:35 -0800 | [diff] [blame] | 110 | void setSidebandStream(const sp<NativeHandle>& stream); |
| 111 | |
| Robert Carr | 82d07c9 | 2021-05-10 11:36:43 -0700 | [diff] [blame] | 112 | uint32_t getLastTransformHint() const; |
| chaviw | 0b020f8 | 2021-08-20 12:00:47 -0500 | [diff] [blame] | 113 | uint64_t getLastAcquiredFrameNum(); |
| Vishnu Nair | 1e8bf10 | 2021-12-28 14:36:59 -0800 | [diff] [blame] | 114 | void abandon(); |
| Robert Carr | 82d07c9 | 2021-05-10 11:36:43 -0700 | [diff] [blame] | 115 | |
| Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 116 | /** |
| 117 | * Set a callback to be invoked when we are hung. The boolean parameter |
| 118 | * indicates whether the hang is due to an unfired fence. |
| 119 | * TODO: The boolean is always true atm, unfired fence is |
| 120 | * the only case we detect. |
| 121 | */ |
| 122 | void setTransactionHangCallback(std::function<void(bool)> callback); |
| 123 | |
| Vishnu Nair | c4a40c1 | 2020-12-23 09:14:32 -0800 | [diff] [blame] | 124 | virtual ~BLASTBufferQueue(); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 125 | |
| 126 | private: |
| Valerie Hau | c5011f9 | 2019-10-11 09:52:07 -0700 | [diff] [blame] | 127 | friend class BLASTBufferQueueHelper; |
| 128 | |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 129 | // can't be copied |
| 130 | BLASTBufferQueue& operator = (const BLASTBufferQueue& rhs); |
| 131 | BLASTBufferQueue(const BLASTBufferQueue& rhs); |
| Vishnu Nair | 8949612 | 2020-12-14 17:14:53 -0800 | [diff] [blame] | 132 | void createBufferQueue(sp<IGraphicBufferProducer>* outProducer, |
| 133 | sp<IGraphicBufferConsumer>* outConsumer); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 134 | |
| chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 135 | void acquireNextBufferLocked( |
| 136 | const std::optional<SurfaceComposerClient::Transaction*> transaction) REQUIRES(mMutex); |
| Vishnu Nair | bf25577 | 2020-10-16 10:54:41 -0700 | [diff] [blame] | 137 | Rect computeCrop(const BufferItem& item) REQUIRES(mMutex); |
| Vishnu Nair | 670b3f7 | 2020-09-29 17:52:18 -0700 | [diff] [blame] | 138 | // Return true if we need to reject the buffer based on the scaling mode and the buffer size. |
| Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 139 | bool rejectBuffer(const BufferItem& item) REQUIRES(mMutex); |
| Vishnu Nair | 8b30dd1 | 2021-01-25 14:16:54 -0800 | [diff] [blame] | 140 | bool maxBuffersAcquired(bool includeExtraAcquire) const REQUIRES(mMutex); |
| chaviw | 497e81c | 2021-02-04 17:09:47 -0800 | [diff] [blame] | 141 | static PixelFormat convertBufferFormat(PixelFormat& format); |
| chaviw | 6a19527 | 2021-09-03 16:14:25 -0500 | [diff] [blame] | 142 | void mergePendingTransactions(SurfaceComposerClient::Transaction* t, uint64_t frameNumber) |
| 143 | REQUIRES(mMutex); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 144 | |
| chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 145 | void flushShadowQueue() REQUIRES(mMutex); |
| 146 | void acquireAndReleaseBuffer() REQUIRES(mMutex); |
| chaviw | 0acd33a | 2021-11-02 11:55:37 -0500 | [diff] [blame] | 147 | void releaseBuffer(const ReleaseCallbackId& callbackId, const sp<Fence>& releaseFence) |
| 148 | REQUIRES(mMutex); |
| 149 | void flushAndWaitForFreeBuffer(std::unique_lock<std::mutex>& lock); |
| chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 150 | |
| Vishnu Nair | dab9409 | 2020-09-29 16:09:04 -0700 | [diff] [blame] | 151 | std::string mName; |
| Vishnu Nair | 2a52ca6 | 2021-06-24 13:08:53 -0700 | [diff] [blame] | 152 | // Represents the queued buffer count from buffer queue, |
| 153 | // pre-BLAST. This is mNumFrameAvailable (buffers that queued to blast) + |
| 154 | // mNumAcquired (buffers that queued to SF) mPendingRelease.size() (buffers that are held by |
| 155 | // blast). This counter is read by android studio profiler. |
| 156 | std::string mQueuedBufferTrace; |
| Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 157 | sp<SurfaceControl> mSurfaceControl; |
| 158 | |
| Vishnu Nair | 1e8bf10 | 2021-12-28 14:36:59 -0800 | [diff] [blame] | 159 | mutable std::mutex mMutex; |
| Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 160 | std::condition_variable mCallbackCV; |
| Valerie Hau | d3b90d2 | 2019-11-06 09:37:31 -0800 | [diff] [blame] | 161 | |
| Valerie Hau | 65b8e87 | 2020-02-13 09:45:14 -0800 | [diff] [blame] | 162 | // BufferQueue internally allows 1 more than |
| 163 | // the max to be acquired |
| Ady Abraham | 0bde6b5 | 2021-05-18 13:57:02 -0700 | [diff] [blame] | 164 | int32_t mMaxAcquiredBuffers = 1; |
| Valerie Hau | a32c552 | 2019-12-09 10:11:08 -0800 | [diff] [blame] | 165 | |
| Vishnu Nair | 1e8bf10 | 2021-12-28 14:36:59 -0800 | [diff] [blame] | 166 | int32_t mNumFrameAvailable GUARDED_BY(mMutex) = 0; |
| 167 | int32_t mNumAcquired GUARDED_BY(mMutex) = 0; |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 168 | |
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 169 | // Keep a reference to the submitted buffers so we can release when surfaceflinger drops the |
| 170 | // buffer or the buffer has been presented and a new buffer is ready to be presented. |
| Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 171 | std::unordered_map<ReleaseCallbackId, BufferItem, ReleaseBufferCallbackIdHash> mSubmitted |
| 172 | GUARDED_BY(mMutex); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 173 | |
| Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 174 | // Keep a queue of the released buffers instead of immediately releasing |
| 175 | // the buffers back to the buffer queue. This would be controlled by SF |
| 176 | // setting the max acquired buffer count. |
| 177 | struct ReleasedBuffer { |
| Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 178 | ReleaseCallbackId callbackId; |
| Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 179 | sp<Fence> releaseFence; |
| 180 | }; |
| 181 | std::deque<ReleasedBuffer> mPendingRelease GUARDED_BY(mMutex); |
| 182 | |
| Vishnu Nair | ea0de00 | 2020-11-17 17:42:37 -0800 | [diff] [blame] | 183 | ui::Size mSize GUARDED_BY(mMutex); |
| 184 | ui::Size mRequestedSize GUARDED_BY(mMutex); |
| chaviw | 565ee54 | 2021-01-14 10:21:23 -0800 | [diff] [blame] | 185 | int32_t mFormat GUARDED_BY(mMutex); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 186 | |
| Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 187 | struct BufferInfo { |
| 188 | bool hasBuffer = false; |
| 189 | uint32_t width; |
| 190 | uint32_t height; |
| 191 | uint32_t transform; |
| 192 | // This is used to check if we should update the blast layer size immediately or wait until |
| 193 | // we get the next buffer. This will support scenarios where the layer can change sizes |
| 194 | // and the buffer will scale to fit the new size. |
| 195 | uint32_t scalingMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW; |
| Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 196 | Rect crop; |
| Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 197 | |
| 198 | void update(bool hasBuffer, uint32_t width, uint32_t height, uint32_t transform, |
| Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 199 | uint32_t scalingMode, const Rect& crop) { |
| Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 200 | this->hasBuffer = hasBuffer; |
| 201 | this->width = width; |
| 202 | this->height = height; |
| 203 | this->transform = transform; |
| 204 | this->scalingMode = scalingMode; |
| Vishnu Nair | 5cc9ac0 | 2021-04-19 13:23:38 -0700 | [diff] [blame] | 205 | if (!crop.isEmpty()) { |
| 206 | this->crop = crop; |
| 207 | } else { |
| 208 | this->crop = Rect(width, height); |
| 209 | } |
| Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 210 | } |
| 211 | }; |
| 212 | |
| 213 | // Last acquired buffer's info. This is used to calculate the correct scale when size change is |
| 214 | // requested. We need to use the old buffer's info to determine what scale we need to apply to |
| 215 | // ensure the correct size. |
| 216 | BufferInfo mLastBufferInfo GUARDED_BY(mMutex); |
| 217 | void setMatrix(SurfaceComposerClient::Transaction* t, const BufferInfo& bufferInfo) |
| 218 | REQUIRES(mMutex); |
| 219 | |
| Valerie Hau | a32c552 | 2019-12-09 10:11:08 -0800 | [diff] [blame] | 220 | uint32_t mTransformHint GUARDED_BY(mMutex); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 221 | |
| 222 | sp<IGraphicBufferConsumer> mConsumer; |
| 223 | sp<IGraphicBufferProducer> mProducer; |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 224 | sp<BLASTBufferItemConsumer> mBufferItemConsumer; |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 225 | |
| Tianhao Yao | 4861b10 | 2022-02-03 20:18:35 +0000 | [diff] [blame] | 226 | std::function<void(SurfaceComposerClient::Transaction*)> mTransactionReadyCallback |
| 227 | GUARDED_BY(mMutex); |
| chaviw | a1c4c82 | 2021-11-10 18:11:58 -0600 | [diff] [blame] | 228 | SurfaceComposerClient::Transaction* mSyncTransaction GUARDED_BY(mMutex); |
| Vishnu Nair | c4a40c1 | 2020-12-23 09:14:32 -0800 | [diff] [blame] | 229 | std::vector<std::tuple<uint64_t /* framenumber */, SurfaceComposerClient::Transaction>> |
| 230 | mPendingTransactions GUARDED_BY(mMutex); |
| 231 | |
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 232 | std::queue<FrameTimelineInfo> mNextFrameTimelineInfoQueue GUARDED_BY(mMutex); |
| Vishnu Nair | 53c936c | 2020-12-03 11:46:37 -0800 | [diff] [blame] | 233 | |
| Vishnu Nair | c4a40c1 | 2020-12-23 09:14:32 -0800 | [diff] [blame] | 234 | // Tracks the last acquired frame number |
| 235 | uint64_t mLastAcquiredFrameNumber GUARDED_BY(mMutex) = 0; |
| 236 | |
| Vishnu Nair | 277142c | 2021-01-05 18:35:29 -0800 | [diff] [blame] | 237 | // Queues up transactions using this token in SurfaceFlinger. This prevents queued up |
| 238 | // transactions from other parts of the client from blocking this transaction. |
| Vishnu Nair | adf632b | 2021-01-07 14:05:08 -0800 | [diff] [blame] | 239 | const sp<IBinder> mApplyToken GUARDED_BY(mMutex) = new BBinder(); |
| 240 | |
| 241 | // Guards access to mDequeueTimestamps since we cannot hold to mMutex in onFrameDequeued or |
| 242 | // we will deadlock. |
| 243 | std::mutex mTimestampMutex; |
| 244 | // Tracks buffer dequeue times by the client. This info is sent to SurfaceFlinger which uses |
| 245 | // it for debugging purposes. |
| 246 | std::unordered_map<uint64_t /* bufferId */, nsecs_t> mDequeueTimestamps |
| 247 | GUARDED_BY(mTimestampMutex); |
| chaviw | 4202616 | 2021-04-16 15:46:12 -0500 | [diff] [blame] | 248 | |
| 249 | // Keep track of SurfaceControls that have submitted a transaction and BBQ is waiting on a |
| 250 | // callback for them. |
| 251 | std::queue<sp<SurfaceControl>> mSurfaceControlsWithPendingCallback GUARDED_BY(mMutex); |
| chaviw | 69058fb | 2021-09-27 09:37:30 -0500 | [diff] [blame] | 252 | |
| 253 | uint32_t mCurrentMaxAcquiredBufferCount; |
| chaviw | 0acd33a | 2021-11-02 11:55:37 -0500 | [diff] [blame] | 254 | |
| 255 | // Flag to determine if syncTransaction should only acquire a single buffer and then clear or |
| 256 | // continue to acquire buffers until explicitly cleared |
| 257 | bool mAcquireSingleBuffer GUARDED_BY(mMutex) = true; |
| Vishnu Nair | d2aaab1 | 2022-02-10 14:49:09 -0800 | [diff] [blame] | 258 | |
| 259 | // True if BBQ will update the destination frame used to scale the buffer to the requested size. |
| 260 | // If false, the caller is responsible for updating the destination frame on the BBQ |
| 261 | // surfacecontol. This is useful if the caller wants to synchronize the buffer scale with |
| 262 | // additional scales in the hierarchy. |
| 263 | bool mUpdateDestinationFrame GUARDED_BY(mMutex) = true; |
| Robert Carr | 79dc06a | 2022-02-22 15:28:59 -0800 | [diff] [blame] | 264 | |
| 265 | // We send all transactions on our apply token over one-way binder calls to avoid blocking |
| 266 | // client threads. All of our transactions remain in order, since they are one-way binder calls |
| 267 | // from a single process, to a single interface. However once we give up a Transaction for sync |
| 268 | // we can start to have ordering issues. When we return from sync to normal frame production, |
| 269 | // we wait on the commit callback of sync frames ensuring ordering, however we don't want to |
| 270 | // wait on the commit callback for every normal frame (since even emitting them has a |
| 271 | // performance cost) this means we need a method to ensure frames are in order when switching |
| 272 | // from one-way application on our apply token, to application on some other apply token. We |
| 273 | // make use of setBufferHasBarrier to declare this ordering. This boolean simply tracks when we |
| 274 | // need to set this flag, notably only in the case where we are transitioning from a previous |
| 275 | // transaction applied by us (one way, may not yet have reached server) and an upcoming |
| 276 | // transaction that will be applied by some sync consumer. |
| 277 | bool mAppliedLastTransaction = false; |
| 278 | uint64_t mLastAppliedFrameNumber = 0; |
| Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 279 | |
| 280 | std::function<void(bool)> mTransactionHangCallback; |
| chaviw | c1cf402 | 2022-06-03 13:32:33 -0500 | [diff] [blame] | 281 | |
| 282 | std::unordered_set<uint64_t> mSyncedFrameNumbers GUARDED_BY(mMutex); |
| Robert Carr | 78c25dd | 2019-08-15 14:10:33 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | } // namespace android |
| 286 | |
| 287 | #endif // ANDROID_GUI_SURFACE_H |