1 /* 2 * Copyright (C) 2017 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 #pragma once 17 18 #include "aemu/base/threads/Thread.h" 19 #include "snapshot/TextureLoader.h" 20 #include "GLcommon/TranslatorIfaces.h" 21 22 #include <EGL/egl.h> 23 24 #include <atomic> 25 #include <memory> 26 27 class GLBackgroundLoader : public android::base::InterruptibleThread { 28 public: GLBackgroundLoader(const android::snapshot::ITextureLoaderWPtr & textureLoaderWeak,const EGLiface & eglIface,const GLESiface & glesIface,SaveableTextureMap & textureMap)29 GLBackgroundLoader(const android::snapshot::ITextureLoaderWPtr& textureLoaderWeak, 30 const EGLiface& eglIface, 31 const GLESiface& glesIface, 32 SaveableTextureMap& textureMap) : 33 m_textureLoaderWPtr(textureLoaderWeak), 34 m_eglIface(eglIface), 35 m_glesIface(glesIface), 36 m_textureMap(textureMap) { } ~GLBackgroundLoader()37 ~GLBackgroundLoader() { 38 wait(nullptr); 39 m_textureMap.clear(); 40 } 41 42 intptr_t main() override; 43 bool wait(intptr_t* exitStatus) override; 44 void interrupt() override; 45 46 private: 47 std::atomic<int> m_loadDelayMs { 10 }; 48 std::atomic<bool> m_interrupted { false }; 49 50 const android::snapshot::ITextureLoaderWPtr m_textureLoaderWPtr; 51 const EGLiface& m_eglIface; 52 const GLESiface& m_glesIface; 53 54 SaveableTextureMap& m_textureMap; 55 }; 56