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 #include "debug_layer_test.h"
17
18 #include <string>
19
20 #include "wrapper_log.h"
21
22 namespace {
23 constexpr const char *MY_LOG_TAG = "DebugLayerTest1";
24 }
25 static GetNextLayerAddr gGetNextLayerAddr = nullptr;
26 static void *gFuncTbl = nullptr;
27
GetNextLayerProc(const char * name)28 static void *GetNextLayerProc(const char *name)
29 {
30 if (gGetNextLayerAddr && gFuncTbl) {
31 return gGetNextLayerAddr(gFuncTbl, name);
32 }
33 WLOGD("-%{public}s- GetNextLayerProc init error.", MY_LOG_TAG);
34 return nullptr;
35 }
36
EglGetDisplay(EGLNativeDisplayType type)37 static EGLDisplay EglGetDisplay(EGLNativeDisplayType type)
38 {
39 WLOGD("-%{public}s-", MY_LOG_TAG);
40 PFNEGLGETDISPLAYPROC next = (PFNEGLGETDISPLAYPROC)GetNextLayerProc("eglGetDisplay");
41 if (next) {
42 return next(type);
43 }
44 return EGL_NO_DISPLAY;
45 }
EglSwapBuffers(EGLDisplay dpy,EGLSurface surface)46 static bool EglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
47 {
48 WLOGE("-%{public}s-", MY_LOG_TAG);
49 PFNEGLSWAPBUFFERSPROC next = (PFNEGLSWAPBUFFERSPROC)GetNextLayerProc("eglSwapBuffers");
50 if (next) {
51 return next(dpy, surface);
52 }
53 return EGL_NO_DISPLAY;
54 }
DebugLayerInitialize(const void * funcTbl,GetNextLayerAddr getAddr)55 __eglMustCastToProperFunctionPointerType DebugLayerInitialize(const void *funcTbl, GetNextLayerAddr getAddr)
56 {
57 WLOGD("-%{public}s-", MY_LOG_TAG);
58 gFuncTbl = const_cast<void *>(funcTbl);
59 gGetNextLayerAddr = getAddr;
60 return nullptr;
61 }
62
DebugLayerGetProcAddr(const char * name,__eglMustCastToProperFunctionPointerType next)63 __eglMustCastToProperFunctionPointerType DebugLayerGetProcAddr(const char *name,
64 __eglMustCastToProperFunctionPointerType next)
65 {
66 WLOGD("-%{public}s- ===name[%{public}s]===", MY_LOG_TAG, name);
67 std::string func(name);
68 if (func == "eglGetDisplay") {
69 WLOGD("-%{public}s-", MY_LOG_TAG);
70 return (__eglMustCastToProperFunctionPointerType)EglGetDisplay;
71 }
72 if (func == "eglSwapBuffers") {
73 WLOGD("-%{public}s-", MY_LOG_TAG);
74 return (__eglMustCastToProperFunctionPointerType)EglSwapBuffers;
75 }
76
77 return next;
78 }
79