blob: 2675643c221ad77c942083d78e9e52b2b64e5ab1 [file] [log] [blame]
Marissa Wallfd668622018-05-10 10:21:13 -07001/*
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
23namespace 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 */
32class BufferQueueLayer : public BufferLayer, public BufferLayerConsumer::ContentsChangedListener {
33public:
Lloyd Pique42ab75e2018-09-12 20:46:03 -070034 explicit BufferQueueLayer(const LayerCreationArgs&);
35 ~BufferQueueLayer() override;
Marissa Wallfd668622018-05-10 10:21:13 -070036
37 // -----------------------------------------------------------------------
38 // Interface implementation for Layer
39 // -----------------------------------------------------------------------
40public:
41 void onLayerDisplayed(const sp<Fence>& releaseFence) override;
42
Marissa Wallfd668622018-05-10 10:21:13 -070043 void setTransformHint(uint32_t orientation) const override;
44
45 std::vector<OccupancyTracker::Segment> getOccupancyHistory(bool forceFlush) override;
46
Lloyd Pique0449b0f2018-12-20 16:23:45 -080047 bool getTransformToDisplayInverse() const override;
Marissa Wallfd668622018-05-10 10:21:13 -070048
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 Krulec010d2192018-10-08 06:29:54 -070056 bool shouldPresentNow(nsecs_t expectedPresentTime) const override;
Marissa Wallfd668622018-05-10 10:21:13 -070057 // -----------------------------------------------------------------------
58
59 // -----------------------------------------------------------------------
60 // Interface implementation for BufferLayer
61 // -----------------------------------------------------------------------
62public:
63 bool fenceHasSignaled() const override;
Ady Abrahamcd1580c2019-04-29 15:40:03 -070064 bool framePresentTimeIsCurrent() const override;
Marissa Wallfd668622018-05-10 10:21:13 -070065
66private:
67 nsecs_t getDesiredPresentTime() override;
Lloyd Pique0449b0f2018-12-20 16:23:45 -080068 std::shared_ptr<FenceTime> getCurrentFenceTime() const override;
Marissa Wallfd668622018-05-10 10:21:13 -070069
Marissa Wall61c58622018-07-18 10:12:20 -070070 void getDrawingTransformMatrix(float *matrix) override;
Lloyd Pique0449b0f2018-12-20 16:23:45 -080071 uint32_t getDrawingTransform() const override;
72 ui::Dataspace getDrawingDataSpace() const override;
73 Rect getDrawingCrop() const override;
Marissa Wallfd668622018-05-10 10:21:13 -070074 uint32_t getDrawingScalingMode() const override;
75 Region getDrawingSurfaceDamage() const override;
76 const HdrMetadata& getDrawingHdrMetadata() const override;
77 int getDrawingApi() const override;
Marissa Wallfd668622018-05-10 10:21:13 -070078
79 uint64_t getFrameNumber() const override;
80
81 bool getAutoRefresh() const override;
82 bool getSidebandStreamChanged() const override;
83
Vishnu Nair6194e2e2019-02-06 12:58:39 -080084 bool latchSidebandStream(bool& recomputeVisibleRegions) override;
Marissa Wallfd668622018-05-10 10:21:13 -070085
Lloyd Pique0449b0f2018-12-20 16:23:45 -080086 bool hasFrameUpdate() const override;
Marissa Wallfd668622018-05-10 10:21:13 -070087
Marissa Wall61c58622018-07-18 10:12:20 -070088 void setFilteringEnabled(bool enabled) override;
Marissa Wallfd668622018-05-10 10:21:13 -070089
Alec Mouri39801c02018-10-10 10:44:47 -070090 status_t bindTextureImage() override;
Alec Mouri56e538f2019-01-14 15:22:01 -080091 status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) override;
Marissa Wallfd668622018-05-10 10:21:13 -070092
Lloyd Pique0449b0f2018-12-20 16:23:45 -080093 status_t updateActiveBuffer() override;
Marissa Wallfd668622018-05-10 10:21:13 -070094 status_t updateFrameNumber(nsecs_t latchTime) override;
95
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080096 void setHwcLayerBuffer(const sp<const DisplayDevice>& displayDevice) override;
Marissa Wallfd668622018-05-10 10:21:13 -070097
98 // -----------------------------------------------------------------------
99 // Interface implementation for BufferLayerConsumer::ContentsChangedListener
100 // -----------------------------------------------------------------------
101protected:
102 void onFrameAvailable(const BufferItem& item) override;
103 void onFrameReplaced(const BufferItem& item) override;
104 void onSidebandStreamChanged() override;
105 // -----------------------------------------------------------------------
106
107public:
108 status_t setDefaultBufferProperties(uint32_t w, uint32_t h, PixelFormat format);
109
110 sp<IGraphicBufferProducer> getProducer() const;
111
112private:
113 // Temporary - Used only for LEGACY camera mode.
114 uint32_t getProducerStickyTransform() const;
115
116 void onFirstRef() override;
117
118 sp<BufferLayerConsumer> mConsumer;
119 sp<IGraphicBufferProducer> mProducer;
120
Marissa Wallfd668622018-05-10 10:21:13 -0700121 // Only accessed on the main thread.
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700122 uint64_t mPreviousFrameNumber{0};
123 bool mUpdateTexImageFailed{false};
Marissa Wallfd668622018-05-10 10:21:13 -0700124
125 // Local copy of the queued contents of the incoming BufferQueue
126 mutable Mutex mQueueItemLock;
127 Condition mQueueItemCondition;
128 Vector<BufferItem> mQueueItems;
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700129 std::atomic<uint64_t> mLastFrameNumberReceived{0};
Marissa Wallfd668622018-05-10 10:21:13 -0700130
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700131 bool mAutoRefresh{false};
132 int mActiveBufferSlot{BufferQueue::INVALID_BUFFER_SLOT};
Marissa Wallfd668622018-05-10 10:21:13 -0700133
134 // thread-safe
Lloyd Piquef1c675b2018-09-12 20:45:39 -0700135 std::atomic<int32_t> mQueuedFrames{0};
136 std::atomic<bool> mSidebandStreamChanged{false};
chaviwf206b662019-01-11 13:07:19 -0800137
138 void fakeVsync();
Marissa Wallfd668622018-05-10 10:21:13 -0700139};
140
141} // namespace android