Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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_BUFFERLAYERCONSUMER_H |
| 18 | #define ANDROID_BUFFERLAYERCONSUMER_H |
| 19 | |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 20 | #include <android-base/thread_annotations.h> |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 21 | #include <gui/BufferQueueDefs.h> |
| 22 | #include <gui/ConsumerBase.h> |
Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 23 | #include <gui/HdrMetadata.h> |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 24 | |
| 25 | #include <ui/FenceTime.h> |
| 26 | #include <ui/GraphicBuffer.h> |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 27 | #include <ui/GraphicTypes.h> |
Chia-I Wu | 67dcc69 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 28 | #include <ui/Region.h> |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 29 | |
| 30 | #include <utils/String8.h> |
| 31 | #include <utils/Vector.h> |
| 32 | #include <utils/threads.h> |
| 33 | |
| 34 | namespace android { |
| 35 | // ---------------------------------------------------------------------------- |
| 36 | |
Chia-I Wu | da5c730 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 37 | class DispSync; |
Chia-I Wu | c75c44d | 2017-11-27 14:32:57 -0800 | [diff] [blame] | 38 | class Layer; |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 39 | class String8; |
| 40 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 41 | namespace renderengine { |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 42 | class RenderEngine; |
| 43 | class Image; |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 44 | } // namespace renderengine |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 45 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 46 | /* |
| 47 | * BufferLayerConsumer consumes buffers of graphics data from a BufferQueue, |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 48 | * and makes them available to RenderEngine as a texture. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 49 | * |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 50 | * A typical usage pattern is to call updateTexImage() when a new frame is |
| 51 | * desired. If a new frame is available, the frame is latched. If not, the |
| 52 | * previous contents are retained. The texture is attached and updated after |
| 53 | * bindTextureImage() is called. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 54 | * |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 55 | * All calls to updateTexImage must be made with RenderEngine being current. |
| 56 | * The texture is attached to the TEXTURE_EXTERNAL texture target. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 57 | */ |
| 58 | class BufferLayerConsumer : public ConsumerBase { |
| 59 | public: |
Chia-I Wu | da5c730 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 60 | static const status_t BUFFER_REJECTED = UNKNOWN_ERROR + 8; |
| 61 | |
| 62 | class BufferRejecter { |
| 63 | friend class BufferLayerConsumer; |
| 64 | virtual bool reject(const sp<GraphicBuffer>& buf, const BufferItem& item) = 0; |
| 65 | |
| 66 | protected: |
| 67 | virtual ~BufferRejecter() {} |
| 68 | }; |
| 69 | |
Chia-I Wu | fd257f8 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 70 | struct ContentsChangedListener : public FrameAvailableListener { |
| 71 | virtual void onSidebandStreamChanged() = 0; |
| 72 | }; |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 73 | |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 74 | // BufferLayerConsumer constructs a new BufferLayerConsumer object. The |
| 75 | // tex parameter indicates the name of the RenderEngine texture to which |
| 76 | // images are to be streamed. |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 77 | BufferLayerConsumer(const sp<IGraphicBufferConsumer>& bq, renderengine::RenderEngine& engine, |
Lloyd Pique | 144e116 | 2017-12-20 16:44:52 -0800 | [diff] [blame] | 78 | uint32_t tex, Layer* layer); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 79 | |
Chia-I Wu | fd257f8 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 80 | // Sets the contents changed listener. This should be used instead of |
| 81 | // ConsumerBase::setFrameAvailableListener(). |
| 82 | void setContentsChangedListener(const wp<ContentsChangedListener>& listener); |
| 83 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 84 | // updateTexImage acquires the most recently queued buffer, and sets the |
| 85 | // image contents of the target texture to it. |
| 86 | // |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 87 | // This call may only be made while RenderEngine is current. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 88 | // |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 89 | // This calls doFenceWait to ensure proper synchronization unless native |
| 90 | // fence is supported. |
Chia-I Wu | da5c730 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 91 | // |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 92 | // Unlike the GLConsumer version, this version takes a functor that may be |
| 93 | // used to reject the newly acquired buffer. It also does not bind the |
| 94 | // RenderEngine texture until bindTextureImage is called. |
Ana Krulec | 010d219 | 2018-10-08 06:29:54 -0700 | [diff] [blame] | 95 | status_t updateTexImage(BufferRejecter* rejecter, nsecs_t expectedPresentTime, |
Alec Mouri | 56e538f | 2019-01-14 15:22:01 -0800 | [diff] [blame] | 96 | bool* autoRefresh, bool* queuedBuffer, uint64_t maxFrameNumber); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 97 | |
Chia-I Wu | 0cb75ac | 2017-11-27 15:56:04 -0800 | [diff] [blame] | 98 | // See BufferLayerConsumer::bindTextureImageLocked(). |
| 99 | status_t bindTextureImage(); |
| 100 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 101 | // setReleaseFence stores a fence that will signal when the current buffer |
| 102 | // is no longer being read. This fence will be returned to the producer |
| 103 | // when the current buffer is released by updateTexImage(). Multiple |
| 104 | // fences can be set for a given buffer; they will be merged into a single |
| 105 | // union fence. |
Chia-I Wu | da5c730 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 106 | void setReleaseFence(const sp<Fence>& fence); |
| 107 | |
| 108 | bool releasePendingBuffer(); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 109 | |
Chia-I Wu | 0cb75ac | 2017-11-27 15:56:04 -0800 | [diff] [blame] | 110 | sp<Fence> getPrevFinalReleaseFence() const; |
| 111 | |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 112 | // See GLConsumer::getTransformMatrix. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 113 | void getTransformMatrix(float mtx[16]); |
| 114 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 115 | // getTimestamp retrieves the timestamp associated with the texture image |
| 116 | // set by the most recent call to updateTexImage. |
| 117 | // |
| 118 | // The timestamp is in nanoseconds, and is monotonically increasing. Its |
| 119 | // other semantics (zero point, etc) are source-dependent and should be |
| 120 | // documented by the source. |
| 121 | int64_t getTimestamp(); |
| 122 | |
| 123 | // getDataSpace retrieves the DataSpace associated with the texture image |
| 124 | // set by the most recent call to updateTexImage. |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 125 | ui::Dataspace getCurrentDataSpace(); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 126 | |
Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 127 | // getCurrentHdrMetadata retrieves the HDR metadata associated with the |
| 128 | // texture image set by the most recent call to updateTexImage. |
| 129 | const HdrMetadata& getCurrentHdrMetadata() const; |
| 130 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 131 | // getFrameNumber retrieves the frame number associated with the texture |
| 132 | // image set by the most recent call to updateTexImage. |
| 133 | // |
| 134 | // The frame number is an incrementing counter set to 0 at the creation of |
| 135 | // the BufferQueue associated with this consumer. |
| 136 | uint64_t getFrameNumber(); |
| 137 | |
Chia-I Wu | 67dcc69 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 138 | bool getTransformToDisplayInverse() const; |
| 139 | |
| 140 | // must be called from SF main thread |
| 141 | const Region& getSurfaceDamage() const; |
| 142 | |
Chia-I Wu | 5c6e463 | 2018-01-11 08:54:38 -0800 | [diff] [blame] | 143 | // getCurrentApi retrieves the API which queues the current buffer. |
| 144 | int getCurrentApi() const; |
| 145 | |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 146 | // See GLConsumer::setDefaultBufferSize. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 147 | status_t setDefaultBufferSize(uint32_t width, uint32_t height); |
| 148 | |
| 149 | // setFilteringEnabled sets whether the transform matrix should be computed |
| 150 | // for use with bilinear filtering. |
| 151 | void setFilteringEnabled(bool enabled); |
| 152 | |
| 153 | // getCurrentBuffer returns the buffer associated with the current image. |
| 154 | // When outSlot is not nullptr, the current buffer slot index is also |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 155 | // returned. Simiarly, when outFence is not nullptr, the current output |
| 156 | // fence is returned. |
| 157 | sp<GraphicBuffer> getCurrentBuffer(int* outSlot = nullptr, sp<Fence>* outFence = nullptr) const; |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 158 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 159 | // getCurrentCrop returns the cropping rectangle of the current buffer. |
| 160 | Rect getCurrentCrop() const; |
| 161 | |
| 162 | // getCurrentTransform returns the transform of the current buffer. |
| 163 | uint32_t getCurrentTransform() const; |
| 164 | |
| 165 | // getCurrentScalingMode returns the scaling mode of the current buffer. |
| 166 | uint32_t getCurrentScalingMode() const; |
| 167 | |
| 168 | // getCurrentFence returns the fence indicating when the current buffer is |
| 169 | // ready to be read from. |
| 170 | sp<Fence> getCurrentFence() const; |
| 171 | |
| 172 | // getCurrentFence returns the FenceTime indicating when the current |
| 173 | // buffer is ready to be read from. |
| 174 | std::shared_ptr<FenceTime> getCurrentFenceTime() const; |
| 175 | |
| 176 | // setConsumerUsageBits overrides the ConsumerBase method to OR |
| 177 | // DEFAULT_USAGE_FLAGS to usage. |
| 178 | status_t setConsumerUsageBits(uint64_t usage); |
Alec Mouri | 485e4c3 | 2019-04-30 18:24:05 -0700 | [diff] [blame^] | 179 | void onBufferAvailable(const BufferItem& item) EXCLUDES(mImagesMutex); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 180 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 181 | protected: |
| 182 | // abandonLocked overrides the ConsumerBase method to clear |
| 183 | // mCurrentTextureImage in addition to the ConsumerBase behavior. |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 184 | virtual void abandonLocked() EXCLUDES(mImagesMutex); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 185 | |
| 186 | // dumpLocked overrides the ConsumerBase method to dump BufferLayerConsumer- |
| 187 | // specific info in addition to the ConsumerBase behavior. |
| 188 | virtual void dumpLocked(String8& result, const char* prefix) const; |
| 189 | |
Alec Mouri | 39801c0 | 2018-10-10 10:44:47 -0700 | [diff] [blame] | 190 | // See ConsumerBase::acquireBufferLocked |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 191 | virtual status_t acquireBufferLocked(BufferItem* item, nsecs_t presentWhen, |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 192 | uint64_t maxFrameNumber = 0) override |
| 193 | EXCLUDES(mImagesMutex); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 194 | |
Chia-I Wu | 6748db4 | 2017-12-01 10:53:53 -0800 | [diff] [blame] | 195 | bool canUseImageCrop(const Rect& crop) const; |
| 196 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 197 | struct PendingRelease { |
Chia-I Wu | 6aff69b | 2017-11-27 14:08:48 -0800 | [diff] [blame] | 198 | PendingRelease() : isPending(false), currentTexture(-1), graphicBuffer() {} |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 199 | |
| 200 | bool isPending; |
| 201 | int currentTexture; |
| 202 | sp<GraphicBuffer> graphicBuffer; |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | // This releases the buffer in the slot referenced by mCurrentTexture, |
| 206 | // then updates state to refer to the BufferItem, which must be a |
| 207 | // newly-acquired buffer. If pendingRelease is not null, the parameters |
| 208 | // which would have been passed to releaseBufferLocked upon the successful |
| 209 | // completion of the method will instead be returned to the caller, so that |
| 210 | // it may call releaseBufferLocked itself later. |
| 211 | status_t updateAndReleaseLocked(const BufferItem& item, |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 212 | PendingRelease* pendingRelease = nullptr) |
| 213 | EXCLUDES(mImagesMutex); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 214 | |
Alec Mouri | 39801c0 | 2018-10-10 10:44:47 -0700 | [diff] [blame] | 215 | // Binds mTexName and the current buffer to TEXTURE_EXTERNAL target. |
| 216 | // If the bind succeeds, this calls doFenceWait. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 217 | status_t bindTextureImageLocked(); |
| 218 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 219 | private: |
Alec Mouri | b5c4f35 | 2019-02-19 19:46:38 -0800 | [diff] [blame] | 220 | // Utility class for managing GraphicBuffer references into renderengine |
| 221 | class Image { |
| 222 | public: |
| 223 | Image(sp<GraphicBuffer> graphicBuffer, renderengine::RenderEngine& engine) |
| 224 | : mGraphicBuffer(graphicBuffer), mRE(engine) {} |
| 225 | virtual ~Image(); |
| 226 | const sp<GraphicBuffer>& graphicBuffer() { return mGraphicBuffer; } |
| 227 | |
| 228 | private: |
| 229 | // mGraphicBuffer is the buffer that was used to create this image. |
| 230 | sp<GraphicBuffer> mGraphicBuffer; |
| 231 | // Back-reference into renderengine to initiate cleanup. |
| 232 | renderengine::RenderEngine& mRE; |
| 233 | DISALLOW_COPY_AND_ASSIGN(Image); |
| 234 | }; |
| 235 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 236 | // freeBufferLocked frees up the given buffer slot. If the slot has been |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 237 | // initialized this will release the reference to the GraphicBuffer in |
Alec Mouri | 39801c0 | 2018-10-10 10:44:47 -0700 | [diff] [blame] | 238 | // that slot. Otherwise it has no effect. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 239 | // |
| 240 | // This method must be called with mMutex locked. |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 241 | virtual void freeBufferLocked(int slotIndex) EXCLUDES(mImagesMutex); |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 242 | |
Chia-I Wu | c75c44d | 2017-11-27 14:32:57 -0800 | [diff] [blame] | 243 | // IConsumerListener interface |
| 244 | void onDisconnect() override; |
Chia-I Wu | fd257f8 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 245 | void onSidebandStreamChanged() override; |
Chia-I Wu | c75c44d | 2017-11-27 14:32:57 -0800 | [diff] [blame] | 246 | void addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, |
| 247 | FrameEventHistoryDelta* outDelta) override; |
| 248 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 249 | // computeCurrentTransformMatrixLocked computes the transform matrix for the |
| 250 | // current texture. It uses mCurrentTransform and the current GraphicBuffer |
| 251 | // to compute this matrix and stores it in mCurrentTransformMatrix. |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 252 | // mCurrentTextureImage must not be nullptr. |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 253 | void computeCurrentTransformMatrixLocked(); |
| 254 | |
Chia-I Wu | 3498e3c | 2017-12-01 10:19:38 -0800 | [diff] [blame] | 255 | // doFenceWaitLocked inserts a wait command into the RenderEngine command |
| 256 | // stream to ensure that it is safe for future RenderEngine commands to |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 257 | // access the current texture buffer. |
Chia-I Wu | 3498e3c | 2017-12-01 10:19:38 -0800 | [diff] [blame] | 258 | status_t doFenceWaitLocked() const; |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 259 | |
Alec Mouri | 2ee0dda | 2019-01-30 16:44:43 -0800 | [diff] [blame] | 260 | // getCurrentCropLocked returns the cropping rectangle of the current buffer. |
| 261 | Rect getCurrentCropLocked() const; |
| 262 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 263 | // The default consumer usage flags that BufferLayerConsumer always sets on its |
| 264 | // BufferQueue instance; these will be OR:d with any additional flags passed |
| 265 | // from the BufferLayerConsumer user. In particular, BufferLayerConsumer will always |
| 266 | // consume buffers as hardware textures. |
| 267 | static const uint64_t DEFAULT_USAGE_FLAGS = GraphicBuffer::USAGE_HW_TEXTURE; |
| 268 | |
Alec Mouri | b5c4f35 | 2019-02-19 19:46:38 -0800 | [diff] [blame] | 269 | // mCurrentTextureBuffer is the buffer containing the current texture. It's |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 270 | // possible that this buffer is not associated with any buffer slot, so we |
| 271 | // must track it separately in order to support the getCurrentBuffer method. |
Alec Mouri | b5c4f35 | 2019-02-19 19:46:38 -0800 | [diff] [blame] | 272 | std::shared_ptr<Image> mCurrentTextureBuffer; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 273 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 274 | // mCurrentCrop is the crop rectangle that applies to the current texture. |
| 275 | // It gets set each time updateTexImage is called. |
| 276 | Rect mCurrentCrop; |
| 277 | |
| 278 | // mCurrentTransform is the transform identifier for the current texture. It |
| 279 | // gets set each time updateTexImage is called. |
| 280 | uint32_t mCurrentTransform; |
| 281 | |
| 282 | // mCurrentScalingMode is the scaling mode for the current texture. It gets |
| 283 | // set each time updateTexImage is called. |
| 284 | uint32_t mCurrentScalingMode; |
| 285 | |
| 286 | // mCurrentFence is the fence received from BufferQueue in updateTexImage. |
| 287 | sp<Fence> mCurrentFence; |
| 288 | |
| 289 | // The FenceTime wrapper around mCurrentFence. |
| 290 | std::shared_ptr<FenceTime> mCurrentFenceTime{FenceTime::NO_FENCE}; |
| 291 | |
| 292 | // mCurrentTransformMatrix is the transform matrix for the current texture. |
| 293 | // It gets computed by computeTransformMatrix each time updateTexImage is |
| 294 | // called. |
| 295 | float mCurrentTransformMatrix[16]; |
| 296 | |
| 297 | // mCurrentTimestamp is the timestamp for the current texture. It |
| 298 | // gets set each time updateTexImage is called. |
| 299 | int64_t mCurrentTimestamp; |
| 300 | |
| 301 | // mCurrentDataSpace is the dataspace for the current texture. It |
| 302 | // gets set each time updateTexImage is called. |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 303 | ui::Dataspace mCurrentDataSpace; |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 304 | |
Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 305 | // mCurrentHdrMetadata is the HDR metadata for the current texture. It |
| 306 | // gets set each time updateTexImage is called. |
| 307 | HdrMetadata mCurrentHdrMetadata; |
| 308 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 309 | // mCurrentFrameNumber is the frame counter for the current texture. |
| 310 | // It gets set each time updateTexImage is called. |
| 311 | uint64_t mCurrentFrameNumber; |
| 312 | |
Chia-I Wu | 67dcc69 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 313 | // Indicates this buffer must be transformed by the inverse transform of the screen |
| 314 | // it is displayed onto. This is applied after BufferLayerConsumer::mCurrentTransform. |
| 315 | // This must be set/read from SurfaceFlinger's main thread. |
| 316 | bool mCurrentTransformToDisplayInverse; |
| 317 | |
| 318 | // The portion of this surface that has changed since the previous frame |
| 319 | Region mCurrentSurfaceDamage; |
| 320 | |
Chia-I Wu | 5c6e463 | 2018-01-11 08:54:38 -0800 | [diff] [blame] | 321 | int mCurrentApi; |
| 322 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 323 | uint32_t mDefaultWidth, mDefaultHeight; |
| 324 | |
| 325 | // mFilteringEnabled indicates whether the transform matrix is computed for |
| 326 | // use with bilinear filtering. It defaults to true and is changed by |
| 327 | // setFilteringEnabled(). |
| 328 | bool mFilteringEnabled; |
| 329 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 330 | renderengine::RenderEngine& mRE; |
Chia-I Wu | 9f2db77 | 2017-11-30 21:06:50 -0800 | [diff] [blame] | 331 | |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 332 | // mTexName is the name of the RenderEngine texture to which streamed |
| 333 | // images will be bound when bindTexImage is called. It is set at |
| 334 | // construction time. |
Chia-I Wu | c91077c | 2017-11-27 13:32:04 -0800 | [diff] [blame] | 335 | const uint32_t mTexName; |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 336 | |
Chia-I Wu | c75c44d | 2017-11-27 14:32:57 -0800 | [diff] [blame] | 337 | // The layer for this BufferLayerConsumer |
| 338 | const wp<Layer> mLayer; |
| 339 | |
Chia-I Wu | fd257f8 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 340 | wp<ContentsChangedListener> mContentsChangedListener; |
| 341 | |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 342 | // mCurrentTexture is the buffer slot index of the buffer that is currently |
Chia-I Wu | 221b592 | 2017-12-14 13:59:16 -0800 | [diff] [blame] | 343 | // bound to the RenderEngine texture. It is initialized to INVALID_BUFFER_SLOT, |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 344 | // indicating that no buffer slot is currently bound to the texture. Note, |
| 345 | // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean |
| 346 | // that no buffer is bound to the texture. A call to setBufferCount will |
| 347 | // reset mCurrentTexture to INVALID_BUFFER_SLOT. |
| 348 | int mCurrentTexture; |
Chia-I Wu | da5c730 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 349 | |
Alec Mouri | b5c4f35 | 2019-02-19 19:46:38 -0800 | [diff] [blame] | 350 | // Shadow buffer cache for cleaning up renderengine references. |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 351 | std::shared_ptr<Image> mImages[BufferQueueDefs::NUM_BUFFER_SLOTS] GUARDED_BY(mImagesMutex); |
| 352 | |
| 353 | // Separate mutex guarding the shadow buffer cache. |
| 354 | // mImagesMutex can be manipulated with binder threads (e.g. onBuffersAllocated) |
| 355 | // which is contentious enough that we can't just use mMutex. |
| 356 | mutable std::mutex mImagesMutex; |
Alec Mouri | 39801c0 | 2018-10-10 10:44:47 -0700 | [diff] [blame] | 357 | |
Chia-I Wu | da5c730 | 2017-11-27 14:51:06 -0800 | [diff] [blame] | 358 | // A release that is pending on the receipt of a new release fence from |
| 359 | // presentDisplay |
| 360 | PendingRelease mPendingRelease; |
Chia-I Wu | f140518 | 2017-11-27 11:29:21 -0800 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | // ---------------------------------------------------------------------------- |
| 364 | }; // namespace android |
| 365 | |
| 366 | #endif // ANDROID_BUFFERLAYERCONSUMER_H |