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