1 /* 2 * Copyright (C) 2011 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 #include "RenderThreadInfo.h" 18 19 #include "aemu/base/synchronization/Lock.h" 20 21 #include <unordered_map> 22 #include <unordered_set> 23 24 namespace gfxstream { 25 26 using android::base::AutoLock; 27 using android::base::Stream; 28 using android::base::Lock; 29 30 static thread_local RenderThreadInfo* s_threadInfoPtr; 31 32 struct RenderThreadRegistry { 33 Lock lock; 34 std::unordered_set<RenderThreadInfo*> threadInfos; 35 }; 36 37 static RenderThreadRegistry sRegistry; 38 RenderThreadInfo()39RenderThreadInfo::RenderThreadInfo() { 40 s_threadInfoPtr = this; 41 AutoLock lock(sRegistry.lock); 42 sRegistry.threadInfos.insert(this); 43 } 44 ~RenderThreadInfo()45RenderThreadInfo::~RenderThreadInfo() { 46 s_threadInfoPtr = nullptr; 47 AutoLock lock(sRegistry.lock); 48 sRegistry.threadInfos.erase(this); 49 } 50 get()51RenderThreadInfo* RenderThreadInfo::get() { 52 return s_threadInfoPtr; 53 } 54 55 // Loop over all active render thread infos. Takes the global render thread info lock. forAllRenderThreadInfos(std::function<void (RenderThreadInfo *)> f)56void RenderThreadInfo::forAllRenderThreadInfos(std::function<void(RenderThreadInfo*)> f) { 57 AutoLock lock(sRegistry.lock); 58 for (auto info: sRegistry.threadInfos) { 59 f(info); 60 } 61 } 62 initGl()63void RenderThreadInfo::initGl() { 64 m_glInfo.emplace(); 65 } 66 onSave(Stream * stream)67void RenderThreadInfo::onSave(Stream* stream) { 68 m_glInfo->onSave(stream); 69 } 70 onLoad(Stream * stream)71bool RenderThreadInfo::onLoad(Stream* stream) { 72 return m_glInfo->onLoad(stream); 73 } 74 postLoadRefreshCurrentContextSurfacePtrs()75void RenderThreadInfo::postLoadRefreshCurrentContextSurfacePtrs() { 76 return m_glInfo->postLoadRefreshCurrentContextSurfacePtrs(); 77 } 78 79 } // namespace gfxstream 80