blob: f7d548b6bfe7f8c95451ee0f458ea213a163bcc4 [file] [log] [blame]
Marissa Wall713b63f2018-10-17 15:42:43 -07001/*
2 * Copyright 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 <condition_variable>
20#include <mutex>
21
22#include <ui/GraphicBuffer.h>
23
24namespace android {
25
26class SurfaceManager;
27class EglManager;
28class Program;
29
30class BufferGenerator {
31public:
32 BufferGenerator();
33 ~BufferGenerator();
34
35 /* Get a new fence */
36 status_t get(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence);
37
38 /* Static callback that sets the fence on a particular instance */
39 static void setBuffer(const sp<GraphicBuffer>& buffer, int32_t fence, void* fenceGenerator);
Chavi Weingartena5aedbd2021-04-09 13:37:33 +000040 ui::Size getSize();
Marissa Wall713b63f2018-10-17 15:42:43 -070041
42private:
43 bool mInitialized = false;
44
45 std::unique_ptr<SurfaceManager> mSurfaceManager;
46 std::unique_ptr<EglManager> mEglManager;
47 std::unique_ptr<Program> mProgram;
48
49 std::condition_variable_any mConditionVariable;
50
51 sp<GraphicBuffer> mGraphicBuffer;
52 int32_t mFence = -1;
53 bool mPending = false;
54
55 using Epoch = std::chrono::time_point<std::chrono::steady_clock>;
56 Epoch mEpoch = std::chrono::steady_clock::now();
Chavi Weingartena5aedbd2021-04-09 13:37:33 +000057 ui::Size mBufferSize;
Marissa Wall713b63f2018-10-17 15:42:43 -070058};
59
60} // namespace android