blob: a3ffe86572019a3e804bde3f225023f806c6823d [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);
40
41private:
42 bool mInitialized = false;
43
44 std::unique_ptr<SurfaceManager> mSurfaceManager;
45 std::unique_ptr<EglManager> mEglManager;
46 std::unique_ptr<Program> mProgram;
47
48 std::condition_variable_any mConditionVariable;
49
50 sp<GraphicBuffer> mGraphicBuffer;
51 int32_t mFence = -1;
52 bool mPending = false;
53
54 using Epoch = std::chrono::time_point<std::chrono::steady_clock>;
55 Epoch mEpoch = std::chrono::steady_clock::now();
56};
57
58} // namespace android