| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2018 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 | #pragma once | 
 | 18 |  | 
 | 19 | #include "BufferLayer.h" | 
 | 20 |  | 
 | 21 | #include <utils/String8.h> | 
 | 22 |  | 
 | 23 | namespace android { | 
 | 24 |  | 
 | 25 | /* | 
 | 26 |  * A new BufferQueue and a new BufferLayerConsumer are created when the | 
 | 27 |  * BufferLayer is first referenced. | 
 | 28 |  * | 
 | 29 |  * This also implements onFrameAvailable(), which notifies SurfaceFlinger | 
 | 30 |  * that new data has arrived. | 
 | 31 |  */ | 
 | 32 | class BufferQueueLayer : public BufferLayer, public BufferLayerConsumer::ContentsChangedListener { | 
 | 33 | public: | 
| Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 34 |     explicit BufferQueueLayer(const LayerCreationArgs&); | 
 | 35 |     ~BufferQueueLayer() override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 36 |  | 
 | 37 |     // ----------------------------------------------------------------------- | 
 | 38 |     // Interface implementation for Layer | 
 | 39 |     // ----------------------------------------------------------------------- | 
 | 40 | public: | 
| chaviw | 8a01fa4 | 2019-08-19 12:39:31 -0700 | [diff] [blame] | 41 |     const char* getType() const override { return "BufferQueueLayer"; } | 
 | 42 |  | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 43 |     void onLayerDisplayed(const sp<Fence>& releaseFence) override; | 
 | 44 |  | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 45 |     void setTransformHint(uint32_t orientation) const override; | 
 | 46 |  | 
 | 47 |     std::vector<OccupancyTracker::Segment> getOccupancyHistory(bool forceFlush) override; | 
 | 48 |  | 
| Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 49 |     bool getTransformToDisplayInverse() const override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 50 |  | 
 | 51 |     // If a buffer was replaced this frame, release the former buffer | 
 | 52 |     void releasePendingBuffer(nsecs_t dequeueReadyTime) override; | 
 | 53 |  | 
 | 54 |     void setDefaultBufferSize(uint32_t w, uint32_t h) override; | 
 | 55 |  | 
 | 56 |     int32_t getQueuedFrameCount() const override; | 
 | 57 |  | 
| Ana Krulec | 010d219 | 2018-10-08 06:29:54 -0700 | [diff] [blame] | 58 |     bool shouldPresentNow(nsecs_t expectedPresentTime) const override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 59 |     // ----------------------------------------------------------------------- | 
 | 60 |  | 
 | 61 |     // ----------------------------------------------------------------------- | 
 | 62 |     // Interface implementation for BufferLayer | 
 | 63 |     // ----------------------------------------------------------------------- | 
 | 64 | public: | 
 | 65 |     bool fenceHasSignaled() const override; | 
| Dominik Laskowski | a8955dd | 2019-07-10 10:19:09 -0700 | [diff] [blame] | 66 |     bool framePresentTimeIsCurrent(nsecs_t expectedPresentTime) const override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 67 |  | 
 | 68 | private: | 
 | 69 |     nsecs_t getDesiredPresentTime() override; | 
| Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 70 |     std::shared_ptr<FenceTime> getCurrentFenceTime() const override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 71 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 72 |     void getDrawingTransformMatrix(float *matrix) override; | 
| Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 73 |     uint32_t getDrawingTransform() const override; | 
 | 74 |     ui::Dataspace getDrawingDataSpace() const override; | 
 | 75 |     Rect getDrawingCrop() const override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 76 |     uint32_t getDrawingScalingMode() const override; | 
 | 77 |     Region getDrawingSurfaceDamage() const override; | 
 | 78 |     const HdrMetadata& getDrawingHdrMetadata() const override; | 
 | 79 |     int getDrawingApi() const override; | 
 | 80 |     PixelFormat getPixelFormat() const override; | 
 | 81 |  | 
| Dominik Laskowski | a8955dd | 2019-07-10 10:19:09 -0700 | [diff] [blame] | 82 |     uint64_t getFrameNumber(nsecs_t expectedPresentTime) const override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 83 |  | 
 | 84 |     bool getAutoRefresh() const override; | 
 | 85 |     bool getSidebandStreamChanged() const override; | 
 | 86 |  | 
| Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 87 |     bool latchSidebandStream(bool& recomputeVisibleRegions) override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 88 |  | 
| Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 89 |     bool hasFrameUpdate() const override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 90 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 91 |     void setFilteringEnabled(bool enabled) override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 92 |  | 
| Alec Mouri | 39801c0 | 2018-10-10 10:44:47 -0700 | [diff] [blame] | 93 |     status_t bindTextureImage() override; | 
| Dominik Laskowski | a8955dd | 2019-07-10 10:19:09 -0700 | [diff] [blame] | 94 |     status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime, | 
 | 95 |                             nsecs_t expectedPresentTime) override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 96 |  | 
| Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 97 |     status_t updateActiveBuffer() override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 98 |     status_t updateFrameNumber(nsecs_t latchTime) override; | 
 | 99 |  | 
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 100 |     void latchPerFrameState(compositionengine::LayerFECompositionState&) const override; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 101 |  | 
 | 102 |     // ----------------------------------------------------------------------- | 
 | 103 |     // Interface implementation for BufferLayerConsumer::ContentsChangedListener | 
 | 104 |     // ----------------------------------------------------------------------- | 
 | 105 | protected: | 
 | 106 |     void onFrameAvailable(const BufferItem& item) override; | 
 | 107 |     void onFrameReplaced(const BufferItem& item) override; | 
 | 108 |     void onSidebandStreamChanged() override; | 
 | 109 |     // ----------------------------------------------------------------------- | 
 | 110 |  | 
 | 111 | public: | 
 | 112 |     status_t setDefaultBufferProperties(uint32_t w, uint32_t h, PixelFormat format); | 
 | 113 |  | 
 | 114 |     sp<IGraphicBufferProducer> getProducer() const; | 
 | 115 |  | 
 | 116 | private: | 
 | 117 |     // Temporary - Used only for LEGACY camera mode. | 
 | 118 |     uint32_t getProducerStickyTransform() const; | 
 | 119 |  | 
 | 120 |     void onFirstRef() override; | 
 | 121 |  | 
 | 122 |     sp<BufferLayerConsumer> mConsumer; | 
 | 123 |     sp<IGraphicBufferProducer> mProducer; | 
 | 124 |  | 
| Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 125 |     PixelFormat mFormat{PIXEL_FORMAT_NONE}; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 126 |  | 
 | 127 |     // Only accessed on the main thread. | 
| Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 128 |     uint64_t mPreviousFrameNumber{0}; | 
 | 129 |     bool mUpdateTexImageFailed{false}; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 130 |  | 
| Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 131 |     uint64_t mPreviousBufferId = 0; | 
 | 132 |     uint64_t mPreviousReleasedFrameNumber = 0; | 
 | 133 |  | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 134 |     // Local copy of the queued contents of the incoming BufferQueue | 
 | 135 |     mutable Mutex mQueueItemLock; | 
 | 136 |     Condition mQueueItemCondition; | 
 | 137 |     Vector<BufferItem> mQueueItems; | 
| Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 138 |     std::atomic<uint64_t> mLastFrameNumberReceived{0}; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 139 |  | 
| Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 140 |     bool mAutoRefresh{false}; | 
 | 141 |     int mActiveBufferSlot{BufferQueue::INVALID_BUFFER_SLOT}; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 142 |  | 
 | 143 |     // thread-safe | 
| Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 144 |     std::atomic<int32_t> mQueuedFrames{0}; | 
 | 145 |     std::atomic<bool> mSidebandStreamChanged{false}; | 
| Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 146 | }; | 
 | 147 |  | 
 | 148 | } // namespace android |