1 /* 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 24 namespace android { 25 26 class SurfaceManager; 27 class EglManager; 28 class Program; 29 30 class BufferGenerator { 31 public: 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 41 private: 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 59