blob: 6cbafb31cece9767976be5870523c88a89e8a043 [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:
chaviw8a01fa42019-08-19 12:39:31 -070041 const char* getType() const override { return "BufferQueueLayer"; }
42
Marissa Wallfd668622018-05-10 10:21:13 -070043 void onLayerDisplayed(const sp<Fence>& releaseFence) override;
44
Marissa Wallfd668622018-05-10 10:21:13 -070045 void setTransformHint(uint32_t orientation) const override;
46
47 std::vector<OccupancyTracker::Segment> getOccupancyHistory(bool forceFlush) override;
48
Marissa Wallfd668622018-05-10 10:21:13 -070049
50 // If a buffer was replaced this frame, release the former buffer
51 void releasePendingBuffer(nsecs_t dequeueReadyTime) override;
52
53 void setDefaultBufferSize(uint32_t w, uint32_t h) override;
54
55 int32_t getQueuedFrameCount() const override;
56
Ana Krulec010d2192018-10-08 06:29:54 -070057 bool shouldPresentNow(nsecs_t expectedPresentTime) const override;
Marissa Wallfd668622018-05-10 10:21:13 -070058 // -----------------------------------------------------------------------
59
60 // -----------------------------------------------------------------------
61 // Interface implementation for BufferLayer
62 // -----------------------------------------------------------------------
63public:
64 bool fenceHasSignaled() const override;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -070065 bool framePresentTimeIsCurrent(nsecs_t expectedPresentTime) const override;
Marissa Wallfd668622018-05-10 10:21:13 -070066
67private:
Marissa Wallfd668622018-05-10 10:21:13 -070068
Dominik Laskowskia8955dd2019-07-10 10:19:09 -070069 uint64_t getFrameNumber(nsecs_t expectedPresentTime) const override;
Marissa Wallfd668622018-05-10 10:21:13 -070070
71 bool getAutoRefresh() const override;
72 bool getSidebandStreamChanged() const override;
73
Vishnu Nair6194e2e2019-02-06 12:58:39 -080074 bool latchSidebandStream(bool& recomputeVisibleRegions) override;
Marissa Wallfd668622018-05-10 10:21:13 -070075
Lloyd Pique0449b0f2018-12-20 16:23:45 -080076 bool hasFrameUpdate() const override;
Marissa Wallfd668622018-05-10 10:21:13 -070077
Marissa Wall61c58622018-07-18 10:12:20 -070078 void setFilteringEnabled(bool enabled) override;
Marissa Wallfd668622018-05-10 10:21:13 -070079
Alec Mouri39801c02018-10-10 10:44:47 -070080 status_t bindTextureImage() override;
Dominik Laskowskia8955dd2019-07-10 10:19:09 -070081 status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime,
82 nsecs_t expectedPresentTime) override;
Marissa Wallfd668622018-05-10 10:21:13 -070083
Lloyd Pique0449b0f2018-12-20 16:23:45 -080084 status_t updateActiveBuffer() override;
Marissa Wallfd668622018-05-10 10:21:13 -070085 status_t updateFrameNumber(nsecs_t latchTime) override;
86
Lloyd Piquef5275482019-01-29 18:42:42 -080087 void latchPerFrameState(compositionengine::LayerFECompositionState&) const override;
Marissa Wallfd668622018-05-10 10:21:13 -070088
89 // -----------------------------------------------------------------------
90 // Interface implementation for BufferLayerConsumer::ContentsChangedListener
91 // -----------------------------------------------------------------------
92protected:
chaviw4244e032019-09-04 11:27:49 -070093 void gatherBufferInfo() override;
94
Marissa Wallfd668622018-05-10 10:21:13 -070095 void onFrameAvailable(const BufferItem& item) override;
96 void onFrameReplaced(const BufferItem& item) override;
97 void onSidebandStreamChanged() override;
98 // -----------------------------------------------------------------------
99
100public:
101 status_t setDefaultBufferProperties(uint32_t w, uint32_t h, PixelFormat format);
102
103 sp<IGraphicBufferProducer> getProducer() const;
104
105private:
106 // Temporary - Used only for LEGACY camera mode.
107 uint32_t getProducerStickyTransform() const;
108
109 void onFirstRef() override;
110
111 sp<BufferLayerConsumer> mConsumer;
112 sp<IGraphicBufferProducer> mProducer;
113
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700114 PixelFormat mFormat{PIXEL_FORMAT_NONE};
Marissa Wallfd668622018-05-10 10:21:13 -0700115
116 // Only accessed on the main thread.
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700117 uint64_t mPreviousFrameNumber{0};
118 bool mUpdateTexImageFailed{false};
Marissa Wallfd668622018-05-10 10:21:13 -0700119
Mikael Pessa2e1608f2019-07-19 11:25:35 -0700120 uint64_t mPreviousBufferId = 0;
121 uint64_t mPreviousReleasedFrameNumber = 0;
122
Marissa Wallfd668622018-05-10 10:21:13 -0700123 // Local copy of the queued contents of the incoming BufferQueue
124 mutable Mutex mQueueItemLock;
125 Condition mQueueItemCondition;
126 Vector<BufferItem> mQueueItems;
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700127 std::atomic<uint64_t> mLastFrameNumberReceived{0};
Marissa Wallfd668622018-05-10 10:21:13 -0700128
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700129 bool mAutoRefresh{false};
130 int mActiveBufferSlot{BufferQueue::INVALID_BUFFER_SLOT};
Marissa Wallfd668622018-05-10 10:21:13 -0700131
132 // thread-safe
Lloyd Piquef1c675b2018-09-12 20:45:39 -0700133 std::atomic<int32_t> mQueuedFrames{0};
134 std::atomic<bool> mSidebandStreamChanged{false};
Marissa Wallfd668622018-05-10 10:21:13 -0700135};
136
137} // namespace android