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 #ifndef FRAMEWORKS_OPENGL_WRAPPER_EGL_PRE_INITIALIZER_H
16 #define FRAMEWORKS_OPENGL_WRAPPER_EGL_PRE_INITIALIZER_H
17 #include "egl_defs.h"
18 #include "thread_private_data_ctl.h"
19 #include "wrapper_log.h"
20 
21 namespace OHOS {
22 class EglPreInitializer {
23 public:
EglPreInitializer()24     EglPreInitializer() noexcept
25     {
26         WLOGD("");
27         int numApis = sizeof(gGlHookNoContext) / sizeof(EglWrapperFuncPointer);
28         EglWrapperFuncPointer *iter = reinterpret_cast<EglWrapperFuncPointer*>(&gGlHookNoContext);
29         for (int i = 0; i < numApis; ++i) {
30             *(iter++) = reinterpret_cast<EglWrapperFuncPointer>(CallGlApiNoContext);
31         }
32         ThreadPrivateDataCtl::SetGlHookTable(&gGlHookNoContext);
33         preInitFlag = true;
34     }
CallGlApiNoContext(void)35     static void CallGlApiNoContext(void)
36     {
37         WLOGE("Call To OpenGL ES API With No Current Context.");
38         return;
39     }
InitStat()40     bool InitStat() const
41     {
42         return preInitFlag;
43     }
44 private:
45     bool preInitFlag = false;
46 };
47 }; // namespace OHOS
48 #endif // FRAMEWORKS_OPENGL_WRAPPER_EGL_PRE_INITIALIZER_H
49