1e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 2e5c31af7Sopenharmony_ci * drawElements Quality Program OpenGL Utilities 3e5c31af7Sopenharmony_ci * --------------------------------------------- 4e5c31af7Sopenharmony_ci * 5e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 10e5c31af7Sopenharmony_ci * 11e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 17e5c31af7Sopenharmony_ci * limitations under the License. 18e5c31af7Sopenharmony_ci * 19e5c31af7Sopenharmony_ci *//*! 20e5c31af7Sopenharmony_ci * \file 21e5c31af7Sopenharmony_ci * \brief OpenGL wrapper implementation. 22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci#include "glwWrapper.hpp" 25e5c31af7Sopenharmony_ci#include "glwFunctions.hpp" 26e5c31af7Sopenharmony_ci#include "deThreadLocal.h" 27e5c31af7Sopenharmony_ci 28e5c31af7Sopenharmony_ci#include <stdexcept> 29e5c31af7Sopenharmony_ci 30e5c31af7Sopenharmony_ciDE_BEGIN_EXTERN_C 31e5c31af7Sopenharmony_ci 32e5c31af7Sopenharmony_ci#include "glwTypes.inl" 33e5c31af7Sopenharmony_ci#include "glwEnums.inl" 34e5c31af7Sopenharmony_ci 35e5c31af7Sopenharmony_ciDE_END_EXTERN_C 36e5c31af7Sopenharmony_ci 37e5c31af7Sopenharmony_cinamespace glw 38e5c31af7Sopenharmony_ci{ 39e5c31af7Sopenharmony_ci 40e5c31af7Sopenharmony_ci#if defined(DE_THREAD_LOCAL) 41e5c31af7Sopenharmony_ci 42e5c31af7Sopenharmony_ci// Thread-local current function table. 43e5c31af7Sopenharmony_ciDE_THREAD_LOCAL const glw::Functions* s_functions = DE_NULL; 44e5c31af7Sopenharmony_ci 45e5c31af7Sopenharmony_civoid setCurrentThreadFunctions (const glw::Functions* gl) 46e5c31af7Sopenharmony_ci{ 47e5c31af7Sopenharmony_ci s_functions = gl; 48e5c31af7Sopenharmony_ci} 49e5c31af7Sopenharmony_ci 50e5c31af7Sopenharmony_ciinline const glw::Functions* getCurrentThreadFunctions (void) 51e5c31af7Sopenharmony_ci{ 52e5c31af7Sopenharmony_ci return s_functions; 53e5c31af7Sopenharmony_ci} 54e5c31af7Sopenharmony_ci 55e5c31af7Sopenharmony_ci#else // defined(DE_THREAD_LOCAL) 56e5c31af7Sopenharmony_ci 57e5c31af7Sopenharmony_cinamespace 58e5c31af7Sopenharmony_ci{ 59e5c31af7Sopenharmony_ci 60e5c31af7Sopenharmony_ciclass FunctionTLSPtr 61e5c31af7Sopenharmony_ci{ 62e5c31af7Sopenharmony_cipublic: 63e5c31af7Sopenharmony_ci FunctionTLSPtr (void) 64e5c31af7Sopenharmony_ci : m_ptr(deThreadLocal_create()) 65e5c31af7Sopenharmony_ci { 66e5c31af7Sopenharmony_ci if (!m_ptr) 67e5c31af7Sopenharmony_ci throw std::runtime_error("glw: TLS allocation failed"); 68e5c31af7Sopenharmony_ci } 69e5c31af7Sopenharmony_ci 70e5c31af7Sopenharmony_ci inline void set (const glw::Functions* gl) 71e5c31af7Sopenharmony_ci { 72e5c31af7Sopenharmony_ci deThreadLocal_set(m_ptr, (void*)gl); 73e5c31af7Sopenharmony_ci } 74e5c31af7Sopenharmony_ci 75e5c31af7Sopenharmony_ci inline const glw::Functions* get (void) const 76e5c31af7Sopenharmony_ci { 77e5c31af7Sopenharmony_ci return (const glw::Functions*)deThreadLocal_get(m_ptr); 78e5c31af7Sopenharmony_ci } 79e5c31af7Sopenharmony_ci 80e5c31af7Sopenharmony_ciprivate: 81e5c31af7Sopenharmony_ci deThreadLocal m_ptr; 82e5c31af7Sopenharmony_ci}; 83e5c31af7Sopenharmony_ci 84e5c31af7Sopenharmony_ci} // anonymous 85e5c31af7Sopenharmony_ci 86e5c31af7Sopenharmony_ci// Initialized in startup. 87e5c31af7Sopenharmony_cistatic FunctionTLSPtr s_functions; 88e5c31af7Sopenharmony_ci 89e5c31af7Sopenharmony_civoid setCurrentThreadFunctions (const glw::Functions* gl) 90e5c31af7Sopenharmony_ci{ 91e5c31af7Sopenharmony_ci s_functions.set(gl); 92e5c31af7Sopenharmony_ci} 93e5c31af7Sopenharmony_ci 94e5c31af7Sopenharmony_ciinline const glw::Functions* getCurrentThreadFunctions (void) 95e5c31af7Sopenharmony_ci{ 96e5c31af7Sopenharmony_ci return s_functions.get(); 97e5c31af7Sopenharmony_ci} 98e5c31af7Sopenharmony_ci 99e5c31af7Sopenharmony_ci#endif // defined(DE_THREAD_LOCAL) 100e5c31af7Sopenharmony_ci 101e5c31af7Sopenharmony_ci} // glw 102e5c31af7Sopenharmony_ci 103e5c31af7Sopenharmony_ciDE_BEGIN_EXTERN_C 104e5c31af7Sopenharmony_ci 105e5c31af7Sopenharmony_ci#include "glwImpl.inl" 106e5c31af7Sopenharmony_ci 107e5c31af7Sopenharmony_ciDE_END_EXTERN_C 108