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), table(nullptr) {} 26 EGLint error; 27 EGLContext ctx; 28 GlHookTable *table; 29 }; 30 31 class ThreadPrivateDataCtl { 32 public: 33 static ThreadPrivateData* GetPrivateData(); 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(); 41 private: 42 static void KeyInit(); 43 static void ValidateKey(); 44 static pthread_key_t key_; 45 static pthread_once_t onceCtl_; 46 }; 47 } // namespace OHOS 48 #endif // FRAMEWORKS_OPENGL_WRAPPER_THREAD_PRIVATE_DATA_H 49