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