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: |
| 41 | void onLayerDisplayed(const sp<Fence>& releaseFence) override; |
| 42 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 43 | void setTransformHint(uint32_t orientation) const override; |
| 44 | |
| 45 | std::vector<OccupancyTracker::Segment> getOccupancyHistory(bool forceFlush) override; |
| 46 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 47 | bool getTransformToDisplayInverse() const override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 48 | |
| 49 | // If a buffer was replaced this frame, release the former buffer |
| 50 | void releasePendingBuffer(nsecs_t dequeueReadyTime) override; |
| 51 | |
| 52 | void setDefaultBufferSize(uint32_t w, uint32_t h) override; |
| 53 | |
| 54 | int32_t getQueuedFrameCount() const override; |
| 55 | |
Ana Krulec | 010d219 | 2018-10-08 06:29:54 -0700 | [diff] [blame] | 56 | bool shouldPresentNow(nsecs_t expectedPresentTime) const override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 57 | // ----------------------------------------------------------------------- |
| 58 | |
| 59 | // ----------------------------------------------------------------------- |
| 60 | // Interface implementation for BufferLayer |
| 61 | // ----------------------------------------------------------------------- |
| 62 | public: |
| 63 | bool fenceHasSignaled() const override; |
Ady Abraham | cd1580c | 2019-04-29 15:40:03 -0700 | [diff] [blame] | 64 | bool framePresentTimeIsCurrent() const override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 65 | |
| 66 | private: |
| 67 | nsecs_t getDesiredPresentTime() override; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 68 | std::shared_ptr<FenceTime> getCurrentFenceTime() const override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 69 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 70 | void getDrawingTransformMatrix(float *matrix) override; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 71 | uint32_t getDrawingTransform() const override; |
| 72 | ui::Dataspace getDrawingDataSpace() const override; |
| 73 | Rect getDrawingCrop() const override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 74 | uint32_t getDrawingScalingMode() const override; |
| 75 | Region getDrawingSurfaceDamage() const override; |
| 76 | const HdrMetadata& getDrawingHdrMetadata() const override; |
| 77 | int getDrawingApi() const override; |
| 78 | PixelFormat getPixelFormat() const override; |
| 79 | |
| 80 | uint64_t getFrameNumber() const override; |
| 81 | |
| 82 | bool getAutoRefresh() const override; |
| 83 | bool getSidebandStreamChanged() const override; |
| 84 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 85 | bool latchSidebandStream(bool& recomputeVisibleRegions) override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 86 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 87 | bool hasFrameUpdate() const override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 88 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 89 | void setFilteringEnabled(bool enabled) override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 90 | |
Alec Mouri | 39801c0 | 2018-10-10 10:44:47 -0700 | [diff] [blame] | 91 | status_t bindTextureImage() override; |
Alec Mouri | 56e538f | 2019-01-14 15:22:01 -0800 | [diff] [blame] | 92 | status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 93 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 94 | status_t updateActiveBuffer() override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 95 | status_t updateFrameNumber(nsecs_t latchTime) override; |
| 96 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 97 | void setHwcLayerBuffer(const sp<const DisplayDevice>& displayDevice) override; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 98 | |
| 99 | // ----------------------------------------------------------------------- |
| 100 | // Interface implementation for BufferLayerConsumer::ContentsChangedListener |
| 101 | // ----------------------------------------------------------------------- |
| 102 | protected: |
| 103 | void onFrameAvailable(const BufferItem& item) override; |
| 104 | void onFrameReplaced(const BufferItem& item) override; |
| 105 | void onSidebandStreamChanged() override; |
| 106 | // ----------------------------------------------------------------------- |
| 107 | |
| 108 | public: |
| 109 | status_t setDefaultBufferProperties(uint32_t w, uint32_t h, PixelFormat format); |
| 110 | |
| 111 | sp<IGraphicBufferProducer> getProducer() const; |
| 112 | |
| 113 | private: |
| 114 | // Temporary - Used only for LEGACY camera mode. |
| 115 | uint32_t getProducerStickyTransform() const; |
| 116 | |
| 117 | void onFirstRef() override; |
| 118 | |
| 119 | sp<BufferLayerConsumer> mConsumer; |
| 120 | sp<IGraphicBufferProducer> mProducer; |
| 121 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 122 | PixelFormat mFormat{PIXEL_FORMAT_NONE}; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 123 | |
| 124 | // Only accessed on the main thread. |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 125 | uint64_t mPreviousFrameNumber{0}; |
| 126 | bool mUpdateTexImageFailed{false}; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 127 | |
| 128 | // Local copy of the queued contents of the incoming BufferQueue |
| 129 | mutable Mutex mQueueItemLock; |
| 130 | Condition mQueueItemCondition; |
| 131 | Vector<BufferItem> mQueueItems; |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 132 | std::atomic<uint64_t> mLastFrameNumberReceived{0}; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 133 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 134 | bool mAutoRefresh{false}; |
| 135 | int mActiveBufferSlot{BufferQueue::INVALID_BUFFER_SLOT}; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 136 | |
| 137 | // thread-safe |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 138 | std::atomic<int32_t> mQueuedFrames{0}; |
| 139 | std::atomic<bool> mSidebandStreamChanged{false}; |
chaviw | f206b66 | 2019-01-11 13:07:19 -0800 | [diff] [blame] | 140 | |
| 141 | void fakeVsync(); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | } // namespace android |