Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 17 | #pragma once |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 18 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 19 | #include <optional> |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 22 | #include <compositionengine/DisplaySurface.h> |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 23 | #include <gui/BufferQueue.h> |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 24 | #include <gui/ConsumerBase.h> |
| 25 | #include <gui/IGraphicBufferProducer.h> |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 26 | #include <ui/DisplayId.h> |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 27 | |
Alec Mouri | ff79387 | 2022-01-13 17:45:06 -0800 | [diff] [blame] | 28 | #include <ui/DisplayIdentification.h> |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 29 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 30 | namespace android { |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 31 | |
| 32 | class HWComposer; |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 33 | class IProducerListener; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 34 | |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 35 | /* This DisplaySurface implementation supports virtual displays, where GPU |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 36 | * and/or HWC compose into a buffer that is then passed to an arbitrary |
| 37 | * consumer (the sink) running in another process. |
| 38 | * |
| 39 | * The simplest case is when the virtual display will never use the h/w |
| 40 | * composer -- either the h/w composer doesn't support writing to buffers, or |
| 41 | * there are more virtual displays than it supports simultaneously. In this |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 42 | * case, the GPU driver works directly with the output buffer queue, and |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 43 | * calls to the VirtualDisplay from SurfaceFlinger and DisplayHardware do |
| 44 | * nothing. |
| 45 | * |
| 46 | * If h/w composer might be used, then each frame will fall into one of three |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 47 | * configurations: GPU-only, HWC-only, and MIXED composition. In all of these, |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 48 | * we must provide a FB target buffer and output buffer for the HWC set() call. |
| 49 | * |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 50 | * In GPU-only composition, the GPU driver is given a buffer from the sink to |
| 51 | * render into. When the GPU driver queues the buffer to the |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 52 | * VirtualDisplaySurface, the VirtualDisplaySurface holds onto it instead of |
| 53 | * immediately queueing it to the sink. The buffer is used as both the FB |
| 54 | * target and output buffer for HWC, though on these frames the HWC doesn't |
| 55 | * do any work for this display and doesn't write to the output buffer. After |
| 56 | * composition is complete, the buffer is queued to the sink. |
| 57 | * |
| 58 | * In HWC-only composition, the VirtualDisplaySurface dequeues a buffer from |
| 59 | * the sink and passes it to HWC as both the FB target buffer and output |
| 60 | * buffer. The HWC doesn't need to read from the FB target buffer, but does |
| 61 | * write to the output buffer. After composition is complete, the buffer is |
| 62 | * queued to the sink. |
| 63 | * |
| 64 | * On MIXED frames, things become more complicated, since some h/w composer |
| 65 | * implementations can't read from and write to the same buffer. This class has |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 66 | * an internal BufferQueue that it uses as a scratch buffer pool. The GPU |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 67 | * driver is given a scratch buffer to render into. When it finishes rendering, |
| 68 | * the buffer is queued and then immediately acquired by the |
| 69 | * VirtualDisplaySurface. The scratch buffer is then used as the FB target |
| 70 | * buffer for HWC, and a separate buffer is dequeued from the sink and used as |
| 71 | * the HWC output buffer. When HWC composition is complete, the scratch buffer |
| 72 | * is released and the output buffer is queued to the sink. |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 73 | */ |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 74 | class VirtualDisplaySurface : public compositionengine::DisplaySurface, |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 75 | public BnGraphicBufferProducer, |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 76 | private ConsumerBase { |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 77 | public: |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 78 | VirtualDisplaySurface(HWComposer&, VirtualDisplayId, const sp<IGraphicBufferProducer>& sink, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 79 | const sp<IGraphicBufferProducer>& bqProducer, |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 80 | const sp<IGraphicBufferConsumer>& bqConsumer, |
| 81 | const std::string& name, bool secure); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 82 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 83 | // |
| 84 | // DisplaySurface interface |
| 85 | // |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 86 | virtual status_t beginFrame(bool mustRecompose); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 87 | virtual status_t prepareFrame(CompositionType); |
Alec Mouri | f97df4d | 2023-09-06 02:10:05 +0000 | [diff] [blame] | 88 | virtual status_t advanceFrame(float hdrSdrRatio); |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 89 | virtual void onFrameCommitted(); |
Dan Stoza | 01049c8 | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 90 | virtual void dumpAsString(String8& result) const; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 91 | virtual void resizeBuffers(const ui::Size&) override; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 92 | virtual const sp<Fence>& getClientTargetAcquireFence() const override; |
Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 93 | // Virtual display surface needs to prepare the frame based on composition type. Skip |
| 94 | // any client composition prediction. |
| 95 | virtual bool supportsCompositionStrategyPrediction() const override { return false; }; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 96 | |
| 97 | private: |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 98 | enum Source : size_t { |
| 99 | SOURCE_SINK = 0, |
| 100 | SOURCE_SCRATCH = 1, |
| 101 | |
| 102 | ftl_first = SOURCE_SINK, |
| 103 | ftl_last = SOURCE_SCRATCH, |
| 104 | }; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 105 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 106 | virtual ~VirtualDisplaySurface(); |
| 107 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 108 | // |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 109 | // IGraphicBufferProducer interface, used by the GPU driver. |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 110 | // |
| 111 | virtual status_t requestBuffer(int pslot, sp<GraphicBuffer>* outBuf); |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 112 | virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers); |
| 113 | virtual status_t setAsyncMode(bool async); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 114 | virtual status_t dequeueBuffer(int* pslot, sp<Fence>*, uint32_t w, uint32_t h, PixelFormat, |
| 115 | uint64_t usage, uint64_t* outBufferAge, |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame] | 116 | FrameEventHistoryDelta* outTimestamps); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 117 | virtual status_t detachBuffer(int slot); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 118 | virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence); |
| 119 | virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>&); |
| 120 | virtual status_t queueBuffer(int pslot, const QueueBufferInput&, QueueBufferOutput*); |
| 121 | virtual status_t cancelBuffer(int pslot, const sp<Fence>&); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 122 | virtual int query(int what, int* value); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 123 | virtual status_t connect(const sp<IProducerListener>&, int api, bool producerControlledByApp, |
| 124 | QueueBufferOutput*); |
| 125 | virtual status_t disconnect(int api, DisconnectMode); |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 126 | virtual status_t setSidebandStream(const sp<NativeHandle>& stream); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 127 | virtual void allocateBuffers(uint32_t width, uint32_t height, PixelFormat, uint64_t usage); |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 128 | virtual status_t allowAllocation(bool allow); |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 129 | virtual status_t setGenerationNumber(uint32_t); |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 130 | virtual String8 getConsumerName() const override; |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 131 | virtual status_t setSharedBufferMode(bool sharedBufferMode) override; |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 132 | virtual status_t setAutoRefresh(bool autoRefresh) override; |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 133 | virtual status_t setDequeueTimeout(nsecs_t timeout) override; |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 134 | virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 135 | sp<Fence>* outFence, float outTransformMatrix[16]) override; |
Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 136 | virtual status_t getUniqueId(uint64_t* outId) const override; |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 137 | virtual status_t getConsumerUsage(uint64_t* outUsage) const override; |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 138 | virtual void setOutputUsage(uint64_t flag); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 139 | |
| 140 | // |
| 141 | // Utility methods |
| 142 | // |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 143 | static Source fbSourceForCompositionType(CompositionType); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 144 | static std::string toString(CompositionType); |
| 145 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 146 | status_t dequeueBuffer(Source, PixelFormat, uint64_t usage, int* sslot, sp<Fence>*); |
| 147 | void updateQueueBufferOutput(QueueBufferOutput&&); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 148 | void resetPerFrameState(); |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 149 | status_t refreshOutputBuffer(); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 150 | |
| 151 | // Both the sink and scratch buffer pools have their own set of slots |
| 152 | // ("source slots", or "sslot"). We have to merge these into the single |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 153 | // set of slots used by the graphics producer ("producer slots" or "pslot") and |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 154 | // internally in the VirtualDisplaySurface. To minimize the number of times |
| 155 | // a producer slot switches which source it comes from, we map source slot |
| 156 | // numbers to producer slot numbers differently for each source. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 157 | static int mapSource2ProducerSlot(Source, int sslot); |
| 158 | static int mapProducer2SourceSlot(Source, int pslot); |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 159 | |
| 160 | // |
| 161 | // Immutable after construction |
| 162 | // |
| 163 | HWComposer& mHwc; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 164 | const VirtualDisplayId mDisplayId; |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 165 | const std::string mDisplayName; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 166 | sp<IGraphicBufferProducer> mSource[2]; // indexed by SOURCE_* |
Jesse Hall | 497ba0e | 2013-11-04 16:43:03 -0800 | [diff] [blame] | 167 | uint32_t mDefaultOutputFormat; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 168 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 169 | // Buffers that HWC has seen before, indexed by HWC slot number. |
| 170 | // NOTE: The BufferQueue slot number is the same as the HWC slot number. |
| 171 | uint64_t mHwcBufferIds[BufferQueue::NUM_BUFFER_SLOTS]; |
| 172 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 173 | // |
| 174 | // Inter-frame state |
| 175 | // |
| 176 | |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 177 | // To avoid buffer reallocations, we track the buffer usage and format |
| 178 | // we used on the previous frame and use it again on the new frame. If |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 179 | // the composition type changes or the GPU driver starts requesting |
Jesse Hall | 1e27ba2 | 2013-09-27 09:05:09 -0700 | [diff] [blame] | 180 | // different usage/format, we'll get a new buffer. |
| 181 | uint32_t mOutputFormat; |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 182 | uint64_t mOutputUsage; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 183 | |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 184 | // Since we present a single producer interface to the GPU driver, but |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 185 | // are internally muxing between the sink and scratch producers, we have |
| 186 | // to keep track of which source last returned each producer slot from |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 187 | // dequeueBuffer. Each bit in mProducerSlotSource corresponds to a producer |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 188 | // slot. Both mProducerSlotSource and mProducerBuffers are indexed by a |
| 189 | // "producer slot"; see the mapSlot*() functions. |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 190 | uint64_t mProducerSlotSource; |
Mathias Agopian | a934764 | 2017-02-13 16:42:28 -0800 | [diff] [blame] | 191 | sp<GraphicBuffer> mProducerBuffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 192 | |
KaiChieh Chuang | c522213 | 2019-12-20 07:38:19 +0800 | [diff] [blame] | 193 | // Need to propagate reallocation to VDS consumer. |
| 194 | // Each bit corresponds to a producer slot. |
| 195 | uint64_t mProducerSlotNeedReallocation; |
| 196 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 197 | // The QueueBufferOutput with the latest info from the sink, and with the |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 198 | // transform hint cleared. Since we defer queueBuffer from the GPU driver |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 199 | // to the sink, we have to return the previous version. |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 200 | // Moves instead of copies are performed to avoid duplicate |
| 201 | // FrameEventHistoryDeltas. |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 202 | QueueBufferOutput mQueueBufferOutput; |
| 203 | |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 204 | // Details of the current sink buffer. These become valid when a buffer is |
| 205 | // dequeued from the sink, and are used when queueing the buffer. |
| 206 | uint32_t mSinkBufferWidth, mSinkBufferHeight; |
| 207 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 208 | // |
| 209 | // Intra-frame state |
| 210 | // |
| 211 | |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 212 | // Composition type and graphics buffer source for the current frame. |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 213 | // Valid after prepareFrame(), cleared in onFrameCommitted. |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 214 | CompositionType mCompositionType = CompositionType::Unknown; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 215 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 216 | // mFbFence is the fence HWC should wait for before reading the framebuffer |
| 217 | // target buffer. |
| 218 | sp<Fence> mFbFence; |
| 219 | |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 220 | // mOutputFence is the fence HWC should wait for before writing to the |
| 221 | // output buffer. |
| 222 | sp<Fence> mOutputFence; |
| 223 | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 224 | // Producer slot numbers for the buffers to use for HWC framebuffer target |
| 225 | // and output. |
| 226 | int mFbProducerSlot; |
| 227 | int mOutputProducerSlot; |
| 228 | |
| 229 | // Debug only -- track the sequence of events in each frame so we can make |
| 230 | // sure they happen in the order we expect. This class implicitly models |
| 231 | // a state machine; this enum/variable makes it explicit. |
| 232 | // |
| 233 | // +-----------+-------------------+-------------+ |
| 234 | // | State | Event || Next State | |
| 235 | // +-----------+-------------------+-------------+ |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 236 | // | Idle | beginFrame || Begun | |
| 237 | // | Begun | prepareFrame || Prepared | |
| 238 | // | Prepared | dequeueBuffer [1] || Gpu | |
| 239 | // | Prepared | advanceFrame [2] || Hwc | |
| 240 | // | Gpu | queueBuffer || GpuDone | |
| 241 | // | GpuDone | advanceFrame || Hwc | |
| 242 | // | Hwc | onFrameCommitted || Idle | |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 243 | // +-----------+-------------------++------------+ |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 244 | // [1] CompositionType::Gpu and CompositionType::Mixed frames. |
| 245 | // [2] CompositionType::Hwc frames. |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 246 | // |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 247 | enum class DebugState { |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 248 | // no buffer dequeued, don't know anything about the next frame |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 249 | Idle, |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 250 | // output buffer dequeued, framebuffer source not yet known |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 251 | Begun, |
Jesse Hall | 028dc8f | 2013-08-20 16:35:32 -0700 | [diff] [blame] | 252 | // output buffer dequeued, framebuffer source known but not provided |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 253 | // to GPU yet. |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 254 | Prepared, |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 255 | // GPU driver has a buffer dequeued |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 256 | Gpu, |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 257 | // GPU driver has queued the buffer, we haven't sent it to HWC yet |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 258 | GpuDone, |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 259 | // HWC has the buffer for this frame |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 260 | Hwc, |
| 261 | |
| 262 | ftl_last = Hwc |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 263 | }; |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 264 | DebugState mDebugState = DebugState::Idle; |
| 265 | CompositionType mDebugLastCompositionType = CompositionType::Unknown; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 266 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 267 | bool mMustRecompose = false; |
Chia-I Wu | 06d63de | 2017-01-04 14:58:51 +0800 | [diff] [blame] | 268 | |
Fabien Sanglard | a34ed63 | 2017-03-14 11:43:52 -0700 | [diff] [blame] | 269 | bool mForceHwcCopy; |
Ramakant Singh | f7e8191 | 2020-04-11 16:02:43 +0530 | [diff] [blame] | 270 | bool mSecure; |
| 271 | int mSinkUsage; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 274 | } // namespace android |