blob: 579ed81f7e7a334838a3784db005f0c6ea9c0b00 [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:
34 BufferQueueLayer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name,
35 uint32_t w, uint32_t h, uint32_t flags);
36
37 // -----------------------------------------------------------------------
38 // Interface implementation for Layer
39 // -----------------------------------------------------------------------
40public:
41 void onLayerDisplayed(const sp<Fence>& releaseFence) override;
42
43 void abandon() override;
44
45 void setTransformHint(uint32_t orientation) const override;
46
47 std::vector<OccupancyTracker::Segment> getOccupancyHistory(bool forceFlush) override;
48
49 bool getTransformToDisplayInverse() const override;
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
58 bool shouldPresentNow(const DispSync& dispSync) const override;
59 // -----------------------------------------------------------------------
60
61 // -----------------------------------------------------------------------
62 // Interface implementation for BufferLayer
63 // -----------------------------------------------------------------------
64public:
65 bool fenceHasSignaled() const override;
66
67private:
68 nsecs_t getDesiredPresentTime() override;
69 std::shared_ptr<FenceTime> getCurrentFenceTime() const override;
70
Marissa Wall61c58622018-07-18 10:12:20 -070071 void getDrawingTransformMatrix(float *matrix) override;
Marissa Wallfd668622018-05-10 10:21:13 -070072 uint32_t getDrawingTransform() const override;
73 ui::Dataspace getDrawingDataSpace() const override;
74 Rect getDrawingCrop() const override;
75 uint32_t getDrawingScalingMode() const override;
76 Region getDrawingSurfaceDamage() const override;
77 const HdrMetadata& getDrawingHdrMetadata() const override;
78 int getDrawingApi() const override;
79 PixelFormat getPixelFormat() const override;
80
81 uint64_t getFrameNumber() const override;
82
83 bool getAutoRefresh() const override;
84 bool getSidebandStreamChanged() const override;
85
86 std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) override;
87
88 bool hasDrawingBuffer() const override;
89
Marissa Wall61c58622018-07-18 10:12:20 -070090 void setFilteringEnabled(bool enabled) override;
Marissa Wallfd668622018-05-10 10:21:13 -070091
92 status_t bindTextureImage() const override;
93 status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) override;
94
95 status_t updateActiveBuffer() override;
96 status_t updateFrameNumber(nsecs_t latchTime) override;
97
98 void setHwcLayerBuffer(const sp<const DisplayDevice>& display) override;
99 // -----------------------------------------------------------------------
100
101 // -----------------------------------------------------------------------
102 // Interface implementation for BufferLayerConsumer::ContentsChangedListener
103 // -----------------------------------------------------------------------
104protected:
105 void onFrameAvailable(const BufferItem& item) override;
106 void onFrameReplaced(const BufferItem& item) override;
107 void onSidebandStreamChanged() override;
108 // -----------------------------------------------------------------------
109
110public:
111 status_t setDefaultBufferProperties(uint32_t w, uint32_t h, PixelFormat format);
112
113 sp<IGraphicBufferProducer> getProducer() const;
114
115private:
116 // Temporary - Used only for LEGACY camera mode.
117 uint32_t getProducerStickyTransform() const;
118
119 void onFirstRef() override;
120
121 sp<BufferLayerConsumer> mConsumer;
122 sp<IGraphicBufferProducer> mProducer;
123
124 PixelFormat mFormat;
125
126 // Only accessed on the main thread.
127 uint64_t mPreviousFrameNumber;
128 bool mUpdateTexImageFailed;
129
130 // Local copy of the queued contents of the incoming BufferQueue
131 mutable Mutex mQueueItemLock;
132 Condition mQueueItemCondition;
133 Vector<BufferItem> mQueueItems;
134 std::atomic<uint64_t> mLastFrameNumberReceived;
135
136 bool mAutoRefresh;
137 int mActiveBufferSlot;
138
139 // thread-safe
140 volatile int32_t mQueuedFrames;
141 volatile int32_t mSidebandStreamChanged; // used like an atomic boolean
142};
143
144} // namespace android