1 // 2 // Copyright 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // global_state.h : Defines functions for querying the thread-local GL and EGL state. 8 9 #ifndef LIBGLESV2_GLOBALSTATE_H_ 10 #define LIBGLESV2_GLOBALSTATE_H_ 11 12 #include "libANGLE/Context.h" 13 #include "libANGLE/Debug.h" 14 #include "libANGLE/Thread.h" 15 #include "libANGLE/features.h" 16 17 #include <mutex> 18 19 namespace angle 20 { 21 using GlobalMutex = std::recursive_mutex; 22 } // namespace angle 23 24 namespace egl 25 { 26 class Debug; 27 class Thread; 28 29 angle::GlobalMutex &GetGlobalMutex(); 30 Thread *GetCurrentThread(); 31 Debug *GetDebug(); 32 void SetContextCurrent(Thread *thread, gl::Context *context); 33 } // namespace egl 34 35 #define ANGLE_SCOPED_GLOBAL_LOCK() \ 36 std::lock_guard<angle::GlobalMutex> globalMutexLock(egl::GetGlobalMutex()) 37 38 namespace gl 39 { 40 extern Context *gSingleThreadedContext; 41 GetGlobalContext()42ANGLE_INLINE Context *GetGlobalContext() 43 { 44 if (gSingleThreadedContext) 45 { 46 return gSingleThreadedContext; 47 } 48 49 egl::Thread *thread = egl::GetCurrentThread(); 50 return thread->getContext(); 51 } 52 GetValidGlobalContext()53ANGLE_INLINE Context *GetValidGlobalContext() 54 { 55 if (gSingleThreadedContext && !gSingleThreadedContext->isContextLost()) 56 { 57 return gSingleThreadedContext; 58 } 59 60 egl::Thread *thread = egl::GetCurrentThread(); 61 return thread->getValidContext(); 62 } 63 GetShareGroupLock(const Context * context)64ANGLE_INLINE std::unique_lock<angle::GlobalMutex> GetShareGroupLock(const Context *context) 65 { 66 return context->isShared() ? std::unique_lock<angle::GlobalMutex>(egl::GetGlobalMutex()) 67 : std::unique_lock<angle::GlobalMutex>(); 68 } 69 } // namespace gl 70 71 #endif // LIBGLESV2_GLOBALSTATE_H_ 72