1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FRAMEWORKS_OPENGL_WRAPPER_THREAD_PRIVATE_DATA_H 17 #define FRAMEWORKS_OPENGL_WRAPPER_THREAD_PRIVATE_DATA_H 18 19 #include <pthread.h> 20 #include <EGL/egl.h> 21 22 #include "hook.h" 23 namespace OHOS { 24 struct ThreadPrivateData { ThreadPrivateDataThreadPrivateData25 ThreadPrivateData() : error(EGL_SUCCESS), ctx(nullptr) {} 26 EGLint error; 27 EGLContext ctx; 28 }; 29 30 class ThreadPrivateDataCtl { 31 public: 32 static ThreadPrivateData* GetPrivateData(); 33 static void ClearError(); 34 static void ClearPrivateData(); 35 static EGLint GetError(); 36 static void SetError(EGLint error); 37 static void SetContext(EGLContext ctx); 38 static EGLContext GetContext(); 39 static void SetGlHookTable(GlHookTable *table); 40 static GlHookTable *GetGlHookTable(); GetGlHookTableKey()41 static pthread_key_t GetGlHookTableKey() 42 { 43 return tableKey_; 44 } 45 private: 46 static void KeyInit(); 47 static void ValidateKey(); 48 static pthread_key_t key_; 49 static pthread_key_t tableKey_; 50 static pthread_once_t onceCtl_; 51 }; 52 } // namespace OHOS 53 #endif // FRAMEWORKS_OPENGL_WRAPPER_THREAD_PRIVATE_DATA_H 54