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 #include "egl_wrapper_entry.h"
16
17 #include <map>
18 #include <string>
19
20 #include <EGL/egl.h>
21 #include <EGL/eglext.h>
22 #include <dlfcn.h>
23
24 #include "egl_defs.h"
25 #include "egl_wrapper_context.h"
26 #include "egl_wrapper_display.h"
27 #include "egl_wrapper_loader.h"
28 #include "thread_private_data_ctl.h"
29 #include "window.h"
30 #include "wrapper_log.h"
31 #include "egl_blob_cache.h"
32 #if USE_APS_IGAMESERVICE_FUNC
33 #include "egl_slice_report.h"
34 #include "aps_game_fps_controller.h"
35 #endif
36
37 using namespace OHOS;
38 namespace OHOS {
ClearError()39 static inline void ClearError()
40 {
41 ThreadPrivateDataCtl::ClearError();
42 }
43
ValidateDisplay(EGLDisplay dpy)44 static EglWrapperDisplay *ValidateDisplay(EGLDisplay dpy)
45 {
46 EglWrapperDisplay *display = EglWrapperDisplay::GetWrapperDisplay(dpy);
47 if (!display) {
48 WLOGE("EGLDislay is invalid.");
49 ThreadPrivateDataCtl::SetError(EGL_BAD_DISPLAY);
50 return nullptr;
51 }
52
53 if (!display->IsReady()) {
54 WLOGE("display is not ready.");
55 ThreadPrivateDataCtl::SetError(EGL_NOT_INITIALIZED);
56 return nullptr;
57 }
58 return display;
59 }
60
EglChooseConfigImpl(EGLDisplay dpy,const EGLint * attribList,EGLConfig * configs,EGLint configSize,EGLint * numConfig)61 EGLBoolean EglChooseConfigImpl(EGLDisplay dpy, const EGLint *attribList,
62 EGLConfig *configs, EGLint configSize, EGLint *numConfig)
63 {
64 ClearError();
65 WLOGD("");
66 EglWrapperDisplay *display = ValidateDisplay(dpy);
67 if (!display) {
68 return EGL_FALSE;
69 }
70
71 if (numConfig == nullptr) {
72 WLOGE("EGLint *numConfig is nullptr.");
73 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
74 return EGL_FALSE;
75 }
76
77 EGLBoolean ret = EGL_FALSE;
78 *numConfig = 0;
79
80 EglWrapperDispatchTablePtr table = &gWrapperHook;
81 if (table->isLoad && table->egl.eglChooseConfig) {
82 ret = table->egl.eglChooseConfig(display->GetEglDisplay(),
83 attribList, configs, configSize, numConfig);
84 } else {
85 WLOGE("eglChooseConfig is invalid.");
86 }
87
88 return ret;
89 }
90
EglCopyBuffersImpl(EGLDisplay dpy,EGLSurface surf,NativePixmapType target)91 EGLBoolean EglCopyBuffersImpl(EGLDisplay dpy, EGLSurface surf, NativePixmapType target)
92 {
93 ClearError();
94 WLOGD("");
95 EglWrapperDisplay *display = ValidateDisplay(dpy);
96 if (!display) {
97 return EGL_FALSE;
98 }
99
100 return display->CopyBuffers(surf, target);
101 }
102
EglCreateContextImpl(EGLDisplay dpy,EGLConfig config,EGLContext shareList,const EGLint * attribList)103 EGLContext EglCreateContextImpl(EGLDisplay dpy, EGLConfig config,
104 EGLContext shareList, const EGLint *attribList)
105 {
106 ClearError();
107 WLOGD("");
108 EglWrapperDisplay *display = ValidateDisplay(dpy);
109 if (!display) {
110 return EGL_NO_CONTEXT;
111 }
112
113 return display->CreateEglContext(config, shareList, attribList);
114 }
115
EglCreatePbufferSurfaceImpl(EGLDisplay dpy,EGLConfig config,const EGLint * attribList)116 EGLSurface EglCreatePbufferSurfaceImpl(EGLDisplay dpy, EGLConfig config,
117 const EGLint* attribList)
118 {
119 ClearError();
120 WLOGD("");
121 EglWrapperDisplay *display = ValidateDisplay(dpy);
122 if (!display) {
123 return EGL_NO_CONTEXT;
124 }
125
126 return display->CreatePbufferSurface(config, attribList);
127 }
128
EglCreatePixmapSurfaceImpl(EGLDisplay dpy,EGLConfig config,EGLNativePixmapType pixmap,const EGLint * attribList)129 EGLSurface EglCreatePixmapSurfaceImpl(EGLDisplay dpy, EGLConfig config,
130 EGLNativePixmapType pixmap, const EGLint* attribList)
131 {
132 ClearError();
133 WLOGD("");
134 EglWrapperDisplay *display = ValidateDisplay(dpy);
135 if (!display) {
136 return EGL_NO_CONTEXT;
137 }
138
139 return display->CreatePixmapSurface(config, pixmap, attribList);
140 }
141
EglCreateWindowSurfaceImpl(EGLDisplay dpy,EGLConfig config,NativeWindowType window,const EGLint * attribList)142 EGLSurface EglCreateWindowSurfaceImpl(EGLDisplay dpy,
143 EGLConfig config, NativeWindowType window, const EGLint* attribList)
144 {
145 ClearError();
146 WLOGD("");
147 EglWrapperDisplay *display = ValidateDisplay(dpy);
148 if (!display) {
149 return EGL_NO_SURFACE;
150 }
151
152 return display->CreateEglSurface(config, window, attribList);
153 }
154
EglDestroyContextImpl(EGLDisplay dpy,EGLContext ctx)155 EGLBoolean EglDestroyContextImpl(EGLDisplay dpy, EGLContext ctx)
156 {
157 ClearError();
158 WLOGD("");
159 EglWrapperDisplay *display = ValidateDisplay(dpy);
160 if (!display) {
161 return EGL_FALSE;
162 }
163
164 return display->DestroyEglContext(ctx);
165 }
166
EglDestroySurfaceImpl(EGLDisplay dpy,EGLSurface surf)167 EGLBoolean EglDestroySurfaceImpl(EGLDisplay dpy, EGLSurface surf)
168 {
169 ClearError();
170 WLOGD("");
171 EglWrapperDisplay *display = ValidateDisplay(dpy);
172 if (!display) {
173 return EGL_FALSE;
174 }
175
176 return display->DestroyEglSurface(surf);
177 }
178
EglGetConfigAttribImpl(EGLDisplay dpy,EGLConfig config,EGLint attribute,EGLint * value)179 EGLBoolean EglGetConfigAttribImpl(EGLDisplay dpy, EGLConfig config,
180 EGLint attribute, EGLint *value)
181 {
182 ClearError();
183 WLOGD("");
184 EglWrapperDisplay *display = ValidateDisplay(dpy);
185 if (!display) {
186 return EGL_FALSE;
187 }
188
189 EGLBoolean ret = EGL_FALSE;
190 EglWrapperDispatchTablePtr table = &gWrapperHook;
191 if (table->isLoad && table->egl.eglGetConfigAttrib) {
192 ret = table->egl.eglGetConfigAttrib(display->GetEglDisplay(), config, attribute, value);
193 } else {
194 WLOGE("eglGetConfigAttrib is not found.");
195 }
196 return ret;
197 }
198
EglGetConfigsImpl(EGLDisplay dpy,EGLConfig * configs,EGLint configSize,EGLint * numConfig)199 EGLBoolean EglGetConfigsImpl(EGLDisplay dpy, EGLConfig *configs,
200 EGLint configSize, EGLint *numConfig)
201 {
202 ClearError();
203 WLOGD("");
204 EglWrapperDisplay *display = ValidateDisplay(dpy);
205 if (!display) {
206 return EGL_FALSE;
207 }
208
209 if (numConfig == nullptr) {
210 WLOGE("EGLint *numConfig is nullptr.");
211 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
212 }
213
214 EGLBoolean ret = EGL_FALSE;
215 EglWrapperDispatchTablePtr table = &gWrapperHook;
216 if (table->isLoad && table->egl.eglGetConfigs) {
217 ret = table->egl.eglGetConfigs(display->GetEglDisplay(), configs, configSize, numConfig);
218 } else {
219 WLOGE("eglGetConfigs is not found.");
220 }
221
222 return ret;
223 }
224
EglGetCurrentDisplayImpl(void)225 EGLDisplay EglGetCurrentDisplayImpl(void)
226 {
227 ClearError();
228 EGLContext ctx = ThreadPrivateDataCtl::GetContext();
229 if (ctx) {
230 EglWrapperContext *ctxPtr = EglWrapperContext::GetWrapperContext(ctx);
231 if (ctxPtr == nullptr) {
232 WLOGE("current is bad context.");
233 ThreadPrivateDataCtl::SetError(EGL_BAD_CONTEXT);
234 return EGL_NO_DISPLAY;
235 }
236 return ctxPtr->GetDisplay();
237 }
238 return EGL_NO_DISPLAY;
239 }
240
EglGetCurrentSurfaceImpl(EGLint type)241 EGLSurface EglGetCurrentSurfaceImpl(EGLint type)
242 {
243 ClearError();
244 EGLContext ctx = ThreadPrivateDataCtl::GetContext();
245 if (ctx) {
246 EglWrapperContext *ctxPtr = EglWrapperContext::GetWrapperContext(ctx);
247 if (ctxPtr == nullptr) {
248 WLOGE("current is bad context.");
249 ThreadPrivateDataCtl::SetError(EGL_BAD_CONTEXT);
250 return EGL_NO_SURFACE;
251 }
252 return ctxPtr->GetCurrentSurface(type);
253 }
254 return EGL_NO_SURFACE;
255 }
256
EglGetPlatformDisplayInternal(EGLenum platform,EGLNativeDisplayType type,const EGLAttrib * attribList)257 static EGLDisplay EglGetPlatformDisplayInternal(EGLenum platform,
258 EGLNativeDisplayType type, const EGLAttrib *attribList)
259 {
260 WLOGD("");
261 if (type != EGL_DEFAULT_DISPLAY) {
262 WLOGE("EGLNativeDisplayType is invalid.");
263 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
264 return EGL_NO_DISPLAY;
265 }
266
267 if (platform != EGL_PLATFORM_OHOS_KHR) {
268 WLOGE("EGLenum platform is not EGL_PLATFORM_OHOS_KHR.");
269 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
270 return EGL_NO_DISPLAY;
271 }
272
273 return EglWrapperDisplay::GetEglDisplay(platform, type, attribList);
274 }
275
EglGetDisplayImpl(EGLNativeDisplayType type)276 EGLDisplay EglGetDisplayImpl(EGLNativeDisplayType type)
277 {
278 ClearError();
279 WLOGD("");
280 return EglGetPlatformDisplayInternal(EGL_PLATFORM_OHOS_KHR, type, nullptr);
281 }
282
EglGetErrorImpl(void)283 EGLint EglGetErrorImpl(void)
284 {
285 EGLint ret = EGL_SUCCESS;
286 EglWrapperDispatchTablePtr table = &gWrapperHook;
287 if (table->isLoad && table->egl.eglGetError) {
288 ret = table->egl.eglGetError();
289 } else {
290 WLOGE("eglGetError is not found.");
291 }
292
293 if (ret == EGL_SUCCESS) {
294 ret = ThreadPrivateDataCtl::GetError();
295 }
296
297 return ret;
298 }
299
FindBuiltinWrapper(const char * procname)300 static __eglMustCastToProperFunctionPointerType FindBuiltinWrapper(const char* procname)
301 {
302 #if (defined(__aarch64__) || defined(__x86_64__))
303 static void* dlglv3Handle = dlopen("/system/lib64/libGLESv3.so", RTLD_NOW | RTLD_LOCAL);
304 #else
305 static void* dlglv3Handle = dlopen("/system/lib/platformsdk/libGLESv3.so", RTLD_NOW | RTLD_LOCAL);
306 #endif
307 if (dlglv3Handle == nullptr) {
308 WLOGE("Failed to load GLES library using dl open");
309 return nullptr;
310 }
311 void* proc = dlsym(dlglv3Handle, procname);
312 if (proc) {
313 return (__eglMustCastToProperFunctionPointerType)proc;
314 }
315 return nullptr;
316 }
317
EglGetProcAddressImpl(const char * procname)318 __eglMustCastToProperFunctionPointerType EglGetProcAddressImpl(const char *procname)
319 {
320 ClearError();
321 WLOGD("");
322 if (gExtensionMap.find(procname) != gExtensionMap.end()) {
323 return gExtensionMap.at(procname);
324 }
325
326 __eglMustCastToProperFunctionPointerType addr = FindBuiltinWrapper(procname);
327 if (addr) {
328 return __eglMustCastToProperFunctionPointerType(addr);
329 }
330
331 EglWrapperLoader& loader(EglWrapperLoader::GetInstance());
332 void *func = loader.GetProcAddrFromDriver(procname);
333
334 if (!func) {
335 EglWrapperDispatchTablePtr table = &gWrapperHook;
336 if (table->isLoad && table->egl.eglGetProcAddress) {
337 func = reinterpret_cast<void *>(table->egl.eglGetProcAddress(procname));
338 }
339 }
340
341 if (func) {
342 return __eglMustCastToProperFunctionPointerType(func);
343 }
344
345 WLOGW("FindEglExtApi did not find an entry for %{public}s", procname);
346 return nullptr;
347 }
348
EglInitializeImpl(EGLDisplay dpy,EGLint * major,EGLint * minor)349 EGLBoolean EglInitializeImpl(EGLDisplay dpy, EGLint *major, EGLint *minor)
350 {
351 WLOGD("");
352 #if USE_APS_IGAMESERVICE_FUNC
353 OHOS::GameService::EglSliceReport::GetInstance().InitSliceReport();
354 #endif
355 EglWrapperDisplay *display = EglWrapperDisplay::GetWrapperDisplay(dpy);
356 if (!display) {
357 WLOGE("EGLDislay is invalid.");
358 ThreadPrivateDataCtl::SetError(EGL_BAD_DISPLAY);
359 return EGL_FALSE;
360 }
361
362 return display->Init(major, minor);
363 }
364
EglMakeCurrentImpl(EGLDisplay dpy,EGLSurface draw,EGLSurface read,EGLContext ctx)365 EGLBoolean EglMakeCurrentImpl(EGLDisplay dpy, EGLSurface draw,
366 EGLSurface read, EGLContext ctx)
367 {
368 ClearError();
369 WLOGD("");
370 EglWrapperDisplay *display = ValidateDisplay(dpy);
371 if (!display) {
372 return EGL_FALSE;
373 }
374
375 return display->MakeCurrent(draw, read, ctx);
376 }
377
EglQueryContextImpl(EGLDisplay dpy,EGLContext ctx,EGLint attribute,EGLint * value)378 EGLBoolean EglQueryContextImpl(EGLDisplay dpy, EGLContext ctx,
379 EGLint attribute, EGLint *value)
380 {
381 ClearError();
382 WLOGD("");
383 EglWrapperDisplay *display = ValidateDisplay(dpy);
384 if (!display) {
385 return EGL_FALSE;
386 }
387
388 if (value == nullptr) {
389 WLOGE("EGLint *value is nullptr.");
390 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
391 return EGL_FALSE;
392 }
393
394 return display->QueryContext(ctx, attribute, value);
395 }
396
EglQueryStringImpl(EGLDisplay dpy,EGLint name)397 const char *EglQueryStringImpl(EGLDisplay dpy, EGLint name)
398 {
399 ClearError();
400 #ifdef IS_EMULATOR
401 EGLDisplay actualDpy = EGL_NO_DISPLAY;
402 if (dpy != EGL_NO_DISPLAY) {
403 EglWrapperDisplay *display = ValidateDisplay(dpy);
404 if (!display) {
405 return nullptr;
406 }
407 actualDpy = display->GetEglDisplay();
408 }
409 EglWrapperDispatchTablePtr table = &gWrapperHook;
410 if (table->isLoad && table->egl.eglQueryString) {
411 return table->egl.eglQueryString(actualDpy, name);
412 } else {
413 WLOGE("eglQueryString is not found.");
414 }
415 return nullptr;
416 #else
417 EglWrapperDisplay *display = ValidateDisplay(dpy);
418 if (!display) {
419 return nullptr;
420 }
421
422 switch (name) {
423 case EGL_VENDOR:
424 return display->GetVendorValue();
425 case EGL_VERSION:
426 return display->GetVersionValue();
427 case EGL_EXTENSIONS:
428 return display->GetExtensionValue();
429 case EGL_CLIENT_APIS:
430 return display->GetClientApiValue();
431 default:
432 return nullptr;
433 }
434 #endif // IS_EMULATOR
435 }
436
EglQuerySurfaceImpl(EGLDisplay dpy,EGLSurface surf,EGLint attribute,EGLint * value)437 EGLBoolean EglQuerySurfaceImpl(EGLDisplay dpy, EGLSurface surf,
438 EGLint attribute, EGLint* value)
439 {
440 ClearError();
441 WLOGD("");
442 EglWrapperDisplay *display = ValidateDisplay(dpy);
443 if (!display) {
444 return EGL_FALSE;
445 }
446
447 if (value == nullptr) {
448 WLOGE("EGLint *value is nullptr.");
449 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
450 return EGL_FALSE;
451 }
452
453 return display->QuerySurface(surf, attribute, value);
454 }
455
EglSwapBuffersImpl(EGLDisplay dpy,EGLSurface surf)456 EGLBoolean EglSwapBuffersImpl(EGLDisplay dpy, EGLSurface surf)
457 {
458 ClearError();
459 WLOGD("");
460 #if USE_APS_IGAMESERVICE_FUNC
461 OHOS::GameService::EglSliceReport::GetInstance().AddGraphicCount();
462 OHOS::Rosen::ApsGameFpsController::GetInstance().PowerCtrllofEglswapbuffer();
463 #endif
464 EglWrapperDisplay *display = ValidateDisplay(dpy);
465 if (!display) {
466 return EGL_FALSE;
467 }
468
469 return display->SwapBuffers(surf);
470 }
471
EglTerminateImpl(EGLDisplay dpy)472 EGLBoolean EglTerminateImpl(EGLDisplay dpy)
473 {
474 ClearError();
475 WLOGD("");
476 EglWrapperDisplay *display = ValidateDisplay(dpy);
477 if (!display) {
478 return EGL_FALSE;
479 }
480
481 return display->Terminate();
482 }
483
EglWaitGLImpl(void)484 EGLBoolean EglWaitGLImpl(void)
485 {
486 ClearError();
487 WLOGD("");
488 EGLBoolean ret = EGL_FALSE;
489 EglWrapperDispatchTablePtr table = &gWrapperHook;
490 if (table->isLoad && table->egl.eglWaitGL) {
491 ret = table->egl.eglWaitGL();
492 } else {
493 WLOGE("eglWaitGL is not found.");
494 }
495 return ret;
496 }
497
EglWaitNativeImpl(EGLint engine)498 EGLBoolean EglWaitNativeImpl(EGLint engine)
499 {
500 ClearError();
501 WLOGD("");
502 EGLBoolean ret = EGL_FALSE;
503 EglWrapperDispatchTablePtr table = &gWrapperHook;
504 if (table->isLoad && table->egl.eglWaitNative) {
505 ret = table->egl.eglWaitNative(engine);
506 } else {
507 WLOGE("eglWaitNative is not found.");
508 }
509 return ret;
510 }
511
EglBindTexImageImpl(EGLDisplay dpy,EGLSurface surf,EGLint buffer)512 EGLBoolean EglBindTexImageImpl(EGLDisplay dpy, EGLSurface surf, EGLint buffer)
513 {
514 ClearError();
515 WLOGD("");
516 EglWrapperDisplay *display = ValidateDisplay(dpy);
517 if (!display) {
518 return EGL_FALSE;
519 }
520
521 return display->BindTexImage(surf, buffer);
522 }
523
EglReleaseTexImageImpl(EGLDisplay dpy,EGLSurface surf,EGLint buffer)524 EGLBoolean EglReleaseTexImageImpl(EGLDisplay dpy, EGLSurface surf, EGLint buffer)
525 {
526 ClearError();
527 WLOGD("");
528 EglWrapperDisplay *display = ValidateDisplay(dpy);
529 if (!display) {
530 return EGL_FALSE;
531 }
532
533 return display->ReleaseTexImage(surf, buffer);
534 }
535
EglSurfaceAttribImpl(EGLDisplay dpy,EGLSurface surf,EGLint attribute,EGLint value)536 EGLBoolean EglSurfaceAttribImpl(EGLDisplay dpy, EGLSurface surf,
537 EGLint attribute, EGLint value)
538 {
539 ClearError();
540 WLOGD("");
541 EglWrapperDisplay *display = ValidateDisplay(dpy);
542 if (!display) {
543 return EGL_FALSE;
544 }
545
546 return display->SurfaceAttrib(surf, attribute, value);
547 }
548
EglSwapIntervalImpl(EGLDisplay dpy,EGLint interval)549 EGLBoolean EglSwapIntervalImpl(EGLDisplay dpy, EGLint interval)
550 {
551 ClearError();
552 WLOGD("");
553 EglWrapperDisplay *display = ValidateDisplay(dpy);
554 if (!display) {
555 return EGL_FALSE;
556 }
557
558 EGLBoolean ret = EGL_FALSE;
559 EglWrapperDispatchTablePtr table = &gWrapperHook;
560 if (table->isLoad && table->egl.eglSwapInterval) {
561 ret = table->egl.eglSwapInterval(display->GetEglDisplay(), interval);
562 } else {
563 WLOGE("eglQueryString is not found.");
564 }
565
566 return ret;
567 }
568
EglBindAPIImpl(EGLenum api)569 EGLBoolean EglBindAPIImpl(EGLenum api)
570 {
571 ClearError();
572 WLOGD("");
573 EGLBoolean ret = EGL_FALSE;
574 EglWrapperDispatchTablePtr table = &gWrapperHook;
575 if (table->isLoad && table->egl.eglBindAPI) {
576 ret = table->egl.eglBindAPI(api);
577 } else {
578 WLOGE("eglBindAPI is not found.");
579 }
580 return ret;
581 }
582
EglQueryAPIImpl(void)583 EGLBoolean EglQueryAPIImpl(void)
584 {
585 ClearError();
586 WLOGD("");
587 EglWrapperDispatchTablePtr table = &gWrapperHook;
588 if (table->isLoad && table->egl.eglQueryAPI) {
589 return table->egl.eglQueryAPI();
590 } else {
591 WLOGE("eglQueryAPI is not found.");
592 }
593
594 return EGL_OPENGL_ES_API;
595 }
596
EglCreatePbufferFromClientBufferImpl(EGLDisplay dpy,EGLenum buftype,EGLClientBuffer buffer,EGLConfig config,const EGLint * attribList)597 EGLSurface EglCreatePbufferFromClientBufferImpl(EGLDisplay dpy,
598 EGLenum buftype, EGLClientBuffer buffer,
599 EGLConfig config, const EGLint *attribList)
600 {
601 ClearError();
602 WLOGD("");
603 EglWrapperDisplay *display = ValidateDisplay(dpy);
604 if (!display) {
605 return EGL_NO_SURFACE;
606 }
607
608 return display->CreatePbufferFromClientBuffer(buftype, buffer, config, attribList);
609 }
610
EglReleaseThreadImpl(void)611 EGLBoolean EglReleaseThreadImpl(void)
612 {
613 ClearError();
614 WLOGD("");
615 EglWrapperDispatchTablePtr table = &gWrapperHook;
616 if (table->isLoad && table->egl.eglReleaseThread) {
617 table->egl.eglReleaseThread();
618 } else {
619 WLOGE("eglReleaseThread is not found.");
620 }
621
622 ThreadPrivateDataCtl::ClearPrivateData();
623 return EGL_TRUE;
624 }
625
EglWaitClientImpl(void)626 EGLBoolean EglWaitClientImpl(void)
627 {
628 ClearError();
629 WLOGD("");
630 EGLBoolean ret = EGL_FALSE;
631 EglWrapperDispatchTablePtr table = &gWrapperHook;
632 if (table->isLoad && table->egl.eglWaitClient) {
633 ret = table->egl.eglWaitClient();
634 } else {
635 WLOGE("eglWaitClient is not found.");
636 }
637 return ret;
638 }
639
EglGetCurrentContextImpl(void)640 EGLContext EglGetCurrentContextImpl(void)
641 {
642 ClearError();
643 EGLContext ctx = ThreadPrivateDataCtl::GetContext();
644 return ctx;
645 }
646
EglCreateSyncImpl(EGLDisplay dpy,EGLenum type,const EGLAttrib * attribList)647 EGLSync EglCreateSyncImpl(EGLDisplay dpy, EGLenum type, const EGLAttrib *attribList)
648 {
649 ClearError();
650 WLOGD("");
651 EglWrapperDisplay *display = ValidateDisplay(dpy);
652 if (!display) {
653 return EGL_NO_SYNC;
654 }
655
656 EGLSyncKHR ret = EGL_NO_SYNC;
657 EglWrapperDispatchTablePtr table = &gWrapperHook;
658 if (table->isLoad && table->egl.eglCreateSync) {
659 ret = table->egl.eglCreateSync(display->GetEglDisplay(), type, attribList);
660 } else {
661 WLOGE("eglCreateSync is not found.");
662 }
663
664 return ret;
665 }
666
EglDestroySyncImpl(EGLDisplay dpy,EGLSync sync)667 EGLBoolean EglDestroySyncImpl(EGLDisplay dpy, EGLSync sync)
668 {
669 ClearError();
670 WLOGD("");
671 EglWrapperDisplay *display = ValidateDisplay(dpy);
672 if (!display) {
673 return EGL_FALSE;
674 }
675
676 EGLBoolean ret = EGL_FALSE;
677 EglWrapperDispatchTablePtr table = &gWrapperHook;
678 if (table->isLoad && table->egl.eglDestroySync) {
679 ret = table->egl.eglDestroySync(display->GetEglDisplay(), sync);
680 } else {
681 WLOGE("eglDestroySync is not found.");
682 }
683
684 return ret;
685 }
686
EglClientWaitSyncImpl(EGLDisplay dpy,EGLSync sync,EGLint flags,EGLTimeKHR timeout)687 EGLint EglClientWaitSyncImpl(EGLDisplay dpy, EGLSync sync,
688 EGLint flags, EGLTimeKHR timeout)
689 {
690 ClearError();
691 WLOGD("");
692 EglWrapperDisplay *display = ValidateDisplay(dpy);
693 if (!display) {
694 return EGL_FALSE;
695 }
696
697 EGLBoolean ret = EGL_FALSE;
698 EglWrapperDispatchTablePtr table = &gWrapperHook;
699 if (table->isLoad && table->egl.eglClientWaitSync) {
700 ret = table->egl.eglClientWaitSync(display->GetEglDisplay(),
701 sync, flags, timeout);
702 } else {
703 WLOGE("eglClientWaitSync is not found.");
704 }
705
706 return ret;
707 }
708
EglGetSyncAttribImpl(EGLDisplay dpy,EGLSync sync,EGLint attribute,EGLAttrib * value)709 EGLBoolean EglGetSyncAttribImpl(EGLDisplay dpy, EGLSync sync,
710 EGLint attribute, EGLAttrib *value)
711 {
712 ClearError();
713 WLOGD("");
714 EglWrapperDisplay *display = ValidateDisplay(dpy);
715 if (!display) {
716 return EGL_FALSE;
717 }
718
719 if (value == nullptr) {
720 WLOGE("EGLAttrib *value is nullptr.");
721 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
722 return EGL_FALSE;
723 }
724
725 EGLBoolean ret = EGL_FALSE;
726 EglWrapperDispatchTablePtr table = &gWrapperHook;
727 if (table->isLoad && table->egl.eglGetSyncAttrib) {
728 ret = table->egl.eglGetSyncAttrib(display->GetEglDisplay(),
729 sync, attribute, value);
730 } else {
731 WLOGE("eglGetSyncAttrib is not found.");
732 }
733
734 return ret;
735 }
736
EglCreateImageImpl(EGLDisplay dpy,EGLContext ctx,EGLenum target,EGLClientBuffer buffer,const EGLAttrib * attribList)737 EGLImage EglCreateImageImpl(EGLDisplay dpy, EGLContext ctx,
738 EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attribList)
739 {
740 ClearError();
741 WLOGD("");
742 EglWrapperDisplay *display = ValidateDisplay(dpy);
743 if (!display) {
744 return EGL_NO_IMAGE;
745 }
746
747 return display->CreateImage(ctx, target, buffer, attribList);
748 }
749
EglDestroyImageImpl(EGLDisplay dpy,EGLImage img)750 EGLBoolean EglDestroyImageImpl(EGLDisplay dpy, EGLImage img)
751 {
752 ClearError();
753 WLOGD("");
754 EglWrapperDisplay *display = ValidateDisplay(dpy);
755 if (!display) {
756 return EGL_FALSE;
757 }
758
759 return display->DestroyImage(img);
760 }
761
EglGetPlatformDisplayImpl(EGLenum platform,void * nativeDisplay,const EGLAttrib * attribList)762 EGLDisplay EglGetPlatformDisplayImpl(EGLenum platform,
763 void *nativeDisplay, const EGLAttrib *attribList)
764 {
765 ClearError();
766 return EglGetPlatformDisplayInternal(platform,
767 static_cast<EGLNativeDisplayType>(nativeDisplay), attribList);
768 }
769
EglCreatePlatformWindowSurfaceImpl(EGLDisplay dpy,EGLConfig config,void * nativeWindow,const EGLAttrib * attribList)770 EGLSurface EglCreatePlatformWindowSurfaceImpl(EGLDisplay dpy,
771 EGLConfig config, void *nativeWindow, const EGLAttrib *attribList)
772 {
773 ClearError();
774 WLOGD("");
775 EglWrapperDisplay *display = ValidateDisplay(dpy);
776 if (!display) {
777 return EGL_NO_SURFACE;
778 }
779
780 return display->CreatePlatformWindowSurface(config, nativeWindow, attribList);
781 }
782
783
EglCreatePlatformPixmapSurfaceImpl(EGLDisplay dpy,EGLConfig config,void * nativePixmap,const EGLAttrib * attribList)784 EGLSurface EglCreatePlatformPixmapSurfaceImpl(EGLDisplay dpy,
785 EGLConfig config, void *nativePixmap, const EGLAttrib *attribList)
786 {
787 ClearError();
788 WLOGD("");
789 EglWrapperDisplay *display = ValidateDisplay(dpy);
790 if (!display) {
791 return EGL_NO_SURFACE;
792 }
793
794 return display->CreatePlatformPixmapSurface(config, nativePixmap, attribList);
795 }
796
EglWaitSyncImpl(EGLDisplay dpy,EGLSync sync,EGLint flags)797 EGLBoolean EglWaitSyncImpl(EGLDisplay dpy, EGLSync sync, EGLint flags)
798 {
799 ClearError();
800 WLOGD("");
801 EglWrapperDisplay *display = ValidateDisplay(dpy);
802 if (!display) {
803 return EGL_FALSE;
804 }
805
806 EGLBoolean ret = EGL_FALSE;
807 EglWrapperDispatchTablePtr table = &gWrapperHook;
808 if (table->isLoad && table->egl.eglWaitSync) {
809 ret = table->egl.eglWaitSync(display->GetEglDisplay(), sync, flags);
810 } else {
811 WLOGE("eglWaitSync is not found.");
812 }
813
814 return ret;
815 }
816
EglLockSurfaceKHRImpl(EGLDisplay dpy,EGLSurface surf,const EGLint * attribList)817 EGLBoolean EglLockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surf,
818 const EGLint *attribList)
819 {
820 ClearError();
821 WLOGD("");
822 EglWrapperDisplay *display = ValidateDisplay(dpy);
823 if (!display) {
824 return EGL_FALSE;
825 }
826
827 return display->LockSurfaceKHR(surf, attribList);
828 }
829
EglUnlockSurfaceKHRImpl(EGLDisplay dpy,EGLSurface surf)830 EGLBoolean EglUnlockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surf)
831 {
832 ClearError();
833 WLOGD("");
834 EglWrapperDisplay *display = ValidateDisplay(dpy);
835 if (!display) {
836 return EGL_FALSE;
837 }
838
839 return display->UnlockSurfaceKHR(surf);
840 }
841
EglCreateImageKHRImpl(EGLDisplay dpy,EGLContext ctx,EGLenum target,EGLClientBuffer buffer,const EGLint * attribList)842 EGLImageKHR EglCreateImageKHRImpl(EGLDisplay dpy, EGLContext ctx,
843 EGLenum target, EGLClientBuffer buffer, const EGLint *attribList)
844 {
845 ClearError();
846 WLOGD("");
847 EglWrapperDisplay *display = ValidateDisplay(dpy);
848 if (!display) {
849 return EGL_NO_IMAGE_KHR;
850 }
851
852 return display->CreateImageKHR(ctx, target, buffer, attribList);
853 }
854
EglDestroyImageKHRImpl(EGLDisplay dpy,EGLImageKHR img)855 EGLBoolean EglDestroyImageKHRImpl(EGLDisplay dpy, EGLImageKHR img)
856 {
857 ClearError();
858 WLOGD("");
859 EglWrapperDisplay *display = ValidateDisplay(dpy);
860 if (!display) {
861 return EGL_FALSE;
862 }
863
864 return display->DestroyImageKHR(img);
865 }
866
EglCreateSyncKHRImpl(EGLDisplay dpy,EGLenum type,const EGLint * attribList)867 EGLSyncKHR EglCreateSyncKHRImpl(EGLDisplay dpy, EGLenum type, const EGLint* attribList)
868 {
869 ClearError();
870 WLOGD("");
871 EglWrapperDisplay *display = ValidateDisplay(dpy);
872 if (!display) {
873 return EGL_NO_SYNC_KHR;
874 }
875
876 EGLSyncKHR ret = EGL_NO_SYNC_KHR;
877 EglWrapperDispatchTablePtr table = &gWrapperHook;
878 if (table->isLoad && table->egl.eglCreateSyncKHR) {
879 ret = table->egl.eglCreateSyncKHR(display->GetEglDisplay(), type, attribList);
880 } else {
881 WLOGE("eglCreateSyncKHR is not found.");
882 }
883
884 return ret;
885 }
886
EglDestroySyncKHRImpl(EGLDisplay dpy,EGLSyncKHR sync)887 EGLBoolean EglDestroySyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync)
888 {
889 ClearError();
890 WLOGD("");
891 EglWrapperDisplay *display = ValidateDisplay(dpy);
892 if (!display) {
893 return EGL_FALSE;
894 }
895
896 EGLBoolean ret = EGL_FALSE;
897 EglWrapperDispatchTablePtr table = &gWrapperHook;
898 if (table->isLoad && table->egl.eglDestroySyncKHR) {
899 ret = table->egl.eglDestroySyncKHR(display->GetEglDisplay(), sync);
900 } else {
901 WLOGE("eglDestroySyncKHR is not found.");
902 }
903
904 return ret;
905 }
906
EglClientWaitSyncKHRImpl(EGLDisplay dpy,EGLSyncKHR sync,EGLint flags,EGLTimeKHR timeout)907 EGLint EglClientWaitSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync,
908 EGLint flags, EGLTimeKHR timeout)
909 {
910 ClearError();
911 WLOGD("");
912 EglWrapperDisplay *display = ValidateDisplay(dpy);
913 if (!display) {
914 return EGL_FALSE;
915 }
916
917 EGLBoolean ret = EGL_FALSE;
918 EglWrapperDispatchTablePtr table = &gWrapperHook;
919 if (table->isLoad && table->egl.eglClientWaitSyncKHR) {
920 ret = table->egl.eglClientWaitSyncKHR(display->GetEglDisplay(),
921 sync, flags, timeout);
922 } else {
923 WLOGE("eglClientWaitSyncKHR is not found.");
924 }
925
926 return ret;
927 }
928
EglGetSyncAttribKHRImpl(EGLDisplay dpy,EGLSyncKHR sync,EGLint attribute,EGLint * value)929 EGLBoolean EglGetSyncAttribKHRImpl(EGLDisplay dpy, EGLSyncKHR sync,
930 EGLint attribute, EGLint *value)
931 {
932 ClearError();
933 WLOGD("");
934 EglWrapperDisplay *display = ValidateDisplay(dpy);
935 if (!display) {
936 return EGL_FALSE;
937 }
938
939 if (value == nullptr) {
940 WLOGE("EGLint *value is nullptr.");
941 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
942 return EGL_FALSE;
943 }
944
945 EGLBoolean ret = EGL_FALSE;
946 EglWrapperDispatchTablePtr table = &gWrapperHook;
947 if (table->isLoad && table->egl.eglGetSyncAttribKHR) {
948 ret = table->egl.eglGetSyncAttribKHR(display->GetEglDisplay(),
949 sync, attribute, value);
950 } else {
951 WLOGE("eglGetSyncAttribKHR is not found.");
952 }
953
954 return ret;
955 }
956
EglSignalSyncKHRImpl(EGLDisplay dpy,EGLSyncKHR sync,EGLenum mode)957 EGLBoolean EglSignalSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode)
958 {
959 ClearError();
960 WLOGD("");
961 EglWrapperDisplay *display = ValidateDisplay(dpy);
962 if (!display) {
963 return EGL_FALSE;
964 }
965
966 EGLBoolean ret = EGL_FALSE;
967 EglWrapperDispatchTablePtr table = &gWrapperHook;
968 if (table->isLoad && table->egl.eglSignalSyncKHR) {
969 ret = table->egl.eglSignalSyncKHR(display->GetEglDisplay(), sync, mode);
970 } else {
971 WLOGE("eglSignalSyncKHR is not found.");
972 }
973
974 return ret;
975 }
976
EglCreateStreamKHRImpl(EGLDisplay dpy,const EGLint * attribList)977 EGLStreamKHR EglCreateStreamKHRImpl(EGLDisplay dpy, const EGLint *attribList)
978 {
979 ClearError();
980 WLOGD("");
981 EglWrapperDisplay *display = ValidateDisplay(dpy);
982 if (!display) {
983 return EGL_NO_STREAM_KHR;
984 }
985
986 EGLStreamKHR ret = EGL_NO_STREAM_KHR;
987 EglWrapperDispatchTablePtr table = &gWrapperHook;
988 if (table->isLoad && table->egl.eglCreateStreamKHR) {
989 ret = table->egl.eglCreateStreamKHR(display->GetEglDisplay(), attribList);
990 } else {
991 WLOGE("eglCreateStreamKHR is not found.");
992 }
993
994 return ret;
995 }
996
EglDestroyStreamKHRImpl(EGLDisplay dpy,EGLStreamKHR stream)997 EGLBoolean EglDestroyStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream)
998 {
999 ClearError();
1000 WLOGD("");
1001 EglWrapperDisplay *display = ValidateDisplay(dpy);
1002 if (!display) {
1003 return EGL_FALSE;
1004 }
1005
1006 EGLBoolean ret = EGL_FALSE;
1007 EglWrapperDispatchTablePtr table = &gWrapperHook;
1008 if (table->isLoad && table->egl.eglDestroyStreamKHR) {
1009 ret = table->egl.eglDestroyStreamKHR(display->GetEglDisplay(), stream);
1010 } else {
1011 WLOGE("eglDestroyStreamKHR is not found.");
1012 }
1013
1014 return ret;
1015 }
1016
EglStreamAttribKHRImpl(EGLDisplay dpy,EGLStreamKHR stream,EGLenum attribute,EGLint value)1017 EGLBoolean EglStreamAttribKHRImpl(EGLDisplay dpy, EGLStreamKHR stream,
1018 EGLenum attribute, EGLint value)
1019 {
1020 ClearError();
1021 WLOGD("");
1022 EglWrapperDisplay *display = ValidateDisplay(dpy);
1023 if (!display) {
1024 return EGL_FALSE;
1025 }
1026
1027 EGLBoolean ret = EGL_FALSE;
1028 EglWrapperDispatchTablePtr table = &gWrapperHook;
1029 if (table->isLoad && table->egl.eglStreamAttribKHR) {
1030 ret = table->egl.eglStreamAttribKHR(display->GetEglDisplay(),
1031 stream, attribute, value);
1032 } else {
1033 WLOGE("eglStreamAttribKHR is not found.");
1034 }
1035
1036 return ret;
1037 }
1038
EglQueryStreamKHRImpl(EGLDisplay dpy,EGLStreamKHR stream,EGLenum attribute,EGLint * value)1039 EGLBoolean EglQueryStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream,
1040 EGLenum attribute, EGLint *value)
1041 {
1042 ClearError();
1043 WLOGD("");
1044 EglWrapperDisplay *display = ValidateDisplay(dpy);
1045 if (!display) {
1046 return EGL_FALSE;
1047 }
1048
1049 if (value == nullptr) {
1050 WLOGE("EGLint *value is nullptr.");
1051 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
1052 return EGL_FALSE;
1053 }
1054
1055 EGLBoolean ret = EGL_FALSE;
1056 EglWrapperDispatchTablePtr table = &gWrapperHook;
1057 if (table->isLoad && table->egl.eglQueryStreamKHR) {
1058 ret = table->egl.eglQueryStreamKHR(display->GetEglDisplay(),
1059 stream, attribute, value);
1060 } else {
1061 WLOGE("eglQueryStreamKHR is not found.");
1062 }
1063
1064 return ret;
1065 }
1066
EglQueryStreamu64KHRImpl(EGLDisplay dpy,EGLStreamKHR stream,EGLenum attribute,EGLuint64KHR * value)1067 EGLBoolean EglQueryStreamu64KHRImpl(EGLDisplay dpy, EGLStreamKHR stream,
1068 EGLenum attribute, EGLuint64KHR *value)
1069 {
1070 ClearError();
1071 WLOGD("");
1072 EglWrapperDisplay *display = ValidateDisplay(dpy);
1073 if (!display) {
1074 return EGL_FALSE;
1075 }
1076
1077 if (value == nullptr) {
1078 WLOGE("EGLint *value is nullptr.");
1079 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
1080 return EGL_FALSE;
1081 }
1082
1083 EGLBoolean ret = EGL_FALSE;
1084 EglWrapperDispatchTablePtr table = &gWrapperHook;
1085 if (table->isLoad && table->egl.eglQueryStreamu64KHR) {
1086 ret = table->egl.eglQueryStreamu64KHR(display->GetEglDisplay(),
1087 stream, attribute, value);
1088 } else {
1089 WLOGE("eglQueryStreamu64KHR is not found.");
1090 }
1091
1092 return ret;
1093 }
1094
EglStreamConsumerGLTextureExternalKHRImpl(EGLDisplay dpy,EGLStreamKHR stream)1095 EGLBoolean EglStreamConsumerGLTextureExternalKHRImpl(EGLDisplay dpy,
1096 EGLStreamKHR stream)
1097 {
1098 ClearError();
1099 WLOGD("");
1100 EglWrapperDisplay *display = ValidateDisplay(dpy);
1101 if (!display) {
1102 return EGL_FALSE;
1103 }
1104
1105 EGLBoolean ret = EGL_FALSE;
1106 EglWrapperDispatchTablePtr table = &gWrapperHook;
1107 if (table->isLoad && table->egl.eglStreamConsumerGLTextureExternalKHR) {
1108 ret = table->egl.eglStreamConsumerGLTextureExternalKHR(
1109 display->GetEglDisplay(), stream);
1110 } else {
1111 WLOGE("eglStreamConsumerGLTextureExternalKHR is not found.");
1112 }
1113
1114 return ret;
1115 }
1116
EglStreamConsumerAcquireKHRImpl(EGLDisplay dpy,EGLStreamKHR stream)1117 EGLBoolean EglStreamConsumerAcquireKHRImpl(EGLDisplay dpy, EGLStreamKHR stream)
1118 {
1119 ClearError();
1120 WLOGD("");
1121 EglWrapperDisplay *display = ValidateDisplay(dpy);
1122 if (!display) {
1123 return EGL_FALSE;
1124 }
1125
1126 EGLBoolean ret = EGL_FALSE;
1127 EglWrapperDispatchTablePtr table = &gWrapperHook;
1128 if (table->isLoad && table->egl.eglStreamConsumerAcquireKHR) {
1129 ret = table->egl.eglStreamConsumerAcquireKHR(
1130 display->GetEglDisplay(), stream);
1131 } else {
1132 WLOGE("eglStreamConsumerAcquireKHR is not found.");
1133 }
1134
1135 return ret;
1136 }
1137
EglStreamConsumerReleaseKHRImpl(EGLDisplay dpy,EGLStreamKHR stream)1138 EGLBoolean EglStreamConsumerReleaseKHRImpl(EGLDisplay dpy, EGLStreamKHR stream)
1139 {
1140 ClearError();
1141 WLOGD("");
1142 EglWrapperDisplay *display = ValidateDisplay(dpy);
1143 if (!display) {
1144 return EGL_FALSE;
1145 }
1146
1147 EGLBoolean ret = EGL_FALSE;
1148 EglWrapperDispatchTablePtr table = &gWrapperHook;
1149 if (table->isLoad && table->egl.eglStreamConsumerReleaseKHR) {
1150 ret = table->egl.eglStreamConsumerReleaseKHR(
1151 display->GetEglDisplay(), stream);
1152 } else {
1153 WLOGE("eglStreamConsumerReleaseKHR is not found.");
1154 }
1155
1156 return ret;
1157 }
1158
EglCreateStreamProducerSurfaceKHRImpl(EGLDisplay dpy,EGLConfig config,EGLStreamKHR stream,const EGLint * attribList)1159 EGLSurface EglCreateStreamProducerSurfaceKHRImpl(EGLDisplay dpy, EGLConfig config,
1160 EGLStreamKHR stream, const EGLint *attribList)
1161 {
1162 ClearError();
1163 WLOGD("");
1164 EglWrapperDisplay *display = ValidateDisplay(dpy);
1165 if (!display) {
1166 return EGL_NO_SURFACE;
1167 }
1168
1169 return display->CreateStreamProducerSurfaceKHR(config, stream, attribList);
1170 }
1171
EglQueryStreamTimeKHRImpl(EGLDisplay dpy,EGLStreamKHR stream,EGLenum attribute,EGLTimeKHR * value)1172 EGLBoolean EglQueryStreamTimeKHRImpl(EGLDisplay dpy, EGLStreamKHR stream,
1173 EGLenum attribute, EGLTimeKHR *value)
1174 {
1175 ClearError();
1176 WLOGD("");
1177 EglWrapperDisplay *display = ValidateDisplay(dpy);
1178 if (!display) {
1179 return EGL_FALSE;
1180 }
1181
1182 if (value == nullptr) {
1183 WLOGE("EGLint *value is nullptr.");
1184 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
1185 return EGL_FALSE;
1186 }
1187
1188 EGLBoolean ret = EGL_FALSE;
1189 EglWrapperDispatchTablePtr table = &gWrapperHook;
1190 if (table->isLoad && table->egl.eglQueryStreamTimeKHR) {
1191 ret = table->egl.eglQueryStreamTimeKHR(display->GetEglDisplay(),
1192 stream, attribute, value);
1193 } else {
1194 WLOGE("eglQueryStreamTimeKHR is not found.");
1195 }
1196
1197 return ret;
1198 }
1199
EglGetStreamFileDescriptorKHRImpl(EGLDisplay dpy,EGLStreamKHR stream)1200 EGLNativeFileDescriptorKHR EglGetStreamFileDescriptorKHRImpl(
1201 EGLDisplay dpy, EGLStreamKHR stream)
1202 {
1203 WLOGD("");
1204 EglWrapperDisplay *display = ValidateDisplay(dpy);
1205 if (!display) {
1206 return EGL_NO_FILE_DESCRIPTOR_KHR;
1207 }
1208
1209 EGLNativeFileDescriptorKHR ret = EGL_NO_FILE_DESCRIPTOR_KHR;
1210 EglWrapperDispatchTablePtr table = &gWrapperHook;
1211 if (table->isLoad && table->egl.eglGetStreamFileDescriptorKHR) {
1212 ret = table->egl.eglGetStreamFileDescriptorKHR(
1213 display->GetEglDisplay(), stream);
1214 } else {
1215 WLOGE("eglGetStreamFileDescriptorKHR is not found.");
1216 }
1217
1218 return ret;
1219 }
1220
EglCreateStreamFromFileDescriptorKHRImpl(EGLDisplay dpy,EGLNativeFileDescriptorKHR fd)1221 EGLStreamKHR EglCreateStreamFromFileDescriptorKHRImpl(
1222 EGLDisplay dpy, EGLNativeFileDescriptorKHR fd)
1223 {
1224 ClearError();
1225 WLOGD("");
1226 EglWrapperDisplay *display = ValidateDisplay(dpy);
1227 if (!display) {
1228 return EGL_NO_STREAM_KHR;
1229 }
1230
1231 EGLStreamKHR ret = EGL_NO_STREAM_KHR;
1232 EglWrapperDispatchTablePtr table = &gWrapperHook;
1233 if (table->isLoad && table->egl.eglCreateStreamFromFileDescriptorKHR) {
1234 ret = table->egl.eglCreateStreamFromFileDescriptorKHR(
1235 display->GetEglDisplay(), fd);
1236 } else {
1237 WLOGE("eglCreateStreamFromFileDescriptorKHR is not found.");
1238 }
1239
1240 return ret;
1241 }
1242
EglWaitSyncKHRImpl(EGLDisplay dpy,EGLSyncKHR sync,EGLint flags)1243 EGLBoolean EglWaitSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags)
1244 {
1245 ClearError();
1246 WLOGD("");
1247 EglWrapperDisplay *display = ValidateDisplay(dpy);
1248 if (!display) {
1249 return EGL_FALSE;
1250 }
1251
1252 EGLBoolean ret = EGL_FALSE;
1253 EglWrapperDispatchTablePtr table = &gWrapperHook;
1254 if (table->isLoad && table->egl.eglWaitSyncKHR) {
1255 ret = table->egl.eglWaitSyncKHR(display->GetEglDisplay(), sync, flags);
1256 } else {
1257 WLOGE("eglWaitSyncKHR is not found.");
1258 }
1259
1260 return ret;
1261 }
1262
EglGetPlatformDisplayEXTImpl(EGLenum platform,void * nativeDisplay,const EGLint * attribList)1263 EGLDisplay EglGetPlatformDisplayEXTImpl(EGLenum platform,
1264 void *nativeDisplay, const EGLint *attribList)
1265 {
1266 WLOGD("");
1267 if (nativeDisplay != EGL_DEFAULT_DISPLAY) {
1268 WLOGE("nativeDisplay is invalid.");
1269 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
1270 return EGL_NO_DISPLAY;
1271 }
1272
1273 if (platform != EGL_PLATFORM_OHOS_KHR) {
1274 WLOGE("EGLenum platform is not EGL_PLATFORM_OHOS_KHR.");
1275 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
1276 return EGL_NO_DISPLAY;
1277 }
1278
1279 return EglWrapperDisplay::GetEglDisplayExt(platform, nativeDisplay, attribList);
1280 }
1281
EglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy,EGLSurface draw,EGLint * rects,EGLint nRects)1282 EGLBoolean EglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw,
1283 EGLint *rects, EGLint nRects)
1284 {
1285 ClearError();
1286 WLOGD("");
1287 EglWrapperDisplay *display = ValidateDisplay(dpy);
1288 if (!display) {
1289 return EGL_FALSE;
1290 }
1291
1292 return display->SwapBuffersWithDamageKHR(draw, rects, nRects);
1293 }
1294
EglSetDamageRegionKHRImpl(EGLDisplay dpy,EGLSurface surf,EGLint * rects,EGLint nRects)1295 EGLBoolean EglSetDamageRegionKHRImpl(EGLDisplay dpy, EGLSurface surf,
1296 EGLint *rects, EGLint nRects)
1297 {
1298 ClearError();
1299 WLOGD("");
1300 EglWrapperDisplay *display = ValidateDisplay(dpy);
1301 if (!display) {
1302 return EGL_FALSE;
1303 }
1304
1305 return display->SetDamageRegionKHR(surf, rects, nRects);
1306 }
1307
EglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy,EGLSyncKHR sync)1308 EGLint EglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy, EGLSyncKHR sync)
1309 {
1310 ClearError();
1311 WLOGD("");
1312 EglWrapperDisplay *display = ValidateDisplay(dpy);
1313 if (!display) {
1314 return EGL_FALSE;
1315 }
1316 EGLint ret = -1;
1317 EglWrapperDispatchTablePtr table = &gWrapperHook;
1318 if (table->isLoad && table->egl.eglDupNativeFenceFDANDROID) {
1319 ret = table->egl.eglDupNativeFenceFDANDROID(display->GetEglDisplay(), sync);
1320 } else {
1321 WLOGE("EglDupNativeFenceFDANDROID platform is not found.");
1322 }
1323 return ret;
1324 }
1325
EglSetBlobCacheFuncsANDROIDImpl(EGLDisplay dpy,EGLSetBlobFuncANDROID set,EGLGetBlobFuncANDROID get)1326 void EglSetBlobCacheFuncsANDROIDImpl(EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get)
1327 {
1328 WLOGD("");
1329 EglWrapperDisplay *display = ValidateDisplay(dpy);
1330 if (!display) {
1331 return;
1332 }
1333
1334 EglWrapperDispatchTablePtr table = &gWrapperHook;
1335 if (table->isLoad && table->egl.eglSetBlobCacheFuncsANDROID) {
1336 table->egl.eglSetBlobCacheFuncsANDROID(display->GetEglDisplay(),
1337 BlobCache::SetBlobFunc, BlobCache::GetBlobFunc);
1338 } else {
1339 WLOGE("EglSetBlobCacheFuncsANDROIDImpl platform is not found.");
1340 }
1341 }
1342
EglGetCompositorTimingSupportedANDROIDImpl(EGLDisplay dpy,EGLSurface surface,EGLint name)1343 EGLBoolean EglGetCompositorTimingSupportedANDROIDImpl(EGLDisplay dpy, EGLSurface surface, EGLint name)
1344 {
1345 ClearError();
1346 EglWrapperDisplay *display = ValidateDisplay(dpy);
1347 if (!display) {
1348 return EGL_FALSE;
1349 }
1350 return display->GetCompositorTimingSupportedANDROID(surface, name);
1351 }
1352
EglGetFrameTimestampSupportedANDROIDImpl(EGLDisplay dpy,EGLSurface surface,EGLint timestamp)1353 EGLBoolean EglGetFrameTimestampSupportedANDROIDImpl(EGLDisplay dpy, EGLSurface surface, EGLint timestamp)
1354 {
1355 ClearError();
1356 EglWrapperDisplay *display = ValidateDisplay(dpy);
1357 if (!display) {
1358 return EGL_FALSE;
1359 }
1360 return display->GetFrameTimestampSupportedANDROID(surface, timestamp);
1361 }
1362
EglPresentationTimeANDROIDImpl(EGLDisplay dpy,EGLSurface surface,EGLnsecsANDROID time)1363 EGLBoolean EglPresentationTimeANDROIDImpl(EGLDisplay dpy, EGLSurface surface, EGLnsecsANDROID time)
1364 {
1365 ClearError();
1366 EglWrapperDisplay *display = ValidateDisplay(dpy);
1367 if (!display) {
1368 return EGL_FALSE;
1369 }
1370 return display->PresentationTimeANDROID(surface, time);
1371 }
1372
EglCreatePlatformWindowSurfaceEXTImpl(EGLDisplay dpy,EGLConfig config,void * nativeWindow,const EGLint * attribList)1373 EGLSurface EglCreatePlatformWindowSurfaceEXTImpl(EGLDisplay dpy, EGLConfig config, void *nativeWindow,
1374 const EGLint *attribList)
1375 {
1376 ClearError();
1377 EglWrapperDisplay *display = ValidateDisplay(dpy);
1378 if (!display) {
1379 return EGL_FALSE;
1380 }
1381 return display->CreatePlatformWindowSurfaceEXT(config, nativeWindow, attribList);
1382 }
1383
EglCreatePlatformPixmapSurfaceEXTImpl(EGLDisplay dpy,EGLConfig config,void * nativePixmap,const EGLint * attribList)1384 EGLSurface EglCreatePlatformPixmapSurfaceEXTImpl(EGLDisplay dpy, EGLConfig config, void *nativePixmap,
1385 const EGLint *attribList)
1386 {
1387 ClearError();
1388 EglWrapperDisplay *display = ValidateDisplay(dpy);
1389 if (!display) {
1390 return EGL_FALSE;
1391 }
1392 return display->CreatePlatformPixmapSurfaceEXT(config, nativePixmap, attribList);
1393 }
1394
EglSwapBuffersWithDamageEXTImpl(EGLDisplay dpy,EGLSurface surface,const EGLint * rects,EGLint nRects)1395 EGLBoolean EglSwapBuffersWithDamageEXTImpl(EGLDisplay dpy, EGLSurface surface, const EGLint *rects, EGLint nRects)
1396 {
1397 ClearError();
1398 EglWrapperDisplay *display = ValidateDisplay(dpy);
1399 if (!display) {
1400 return EGL_FALSE;
1401 }
1402 return display->SwapBuffersWithDamageEXT(surface, rects, nRects);
1403 }
1404
EglGetNativeClientBufferANDROIDImpl(const struct AHardwareBuffer * buffer)1405 EGLClientBuffer EglGetNativeClientBufferANDROIDImpl(const struct AHardwareBuffer *buffer)
1406 {
1407 ClearError();
1408 if (buffer == nullptr) {
1409 WLOGE("EGLDislay is invalid.");
1410 ThreadPrivateDataCtl::SetError(EGL_BAD_PARAMETER);
1411 return nullptr;
1412 }
1413
1414 auto nativeWindowBuffer = CreateNativeWindowBufferFromNativeBuffer(reinterpret_cast<OH_NativeBuffer*>(
1415 const_cast<AHardwareBuffer*>(buffer)));
1416 if (nativeWindowBuffer == nullptr) {
1417 WLOGE("EglGetNativeClientBufferANDROIDImpl nativeWindowBuffer is nullptr.");
1418 }
1419 return nativeWindowBuffer;
1420 }
1421
1422 static const std::map<std::string, EglWrapperFuncPointer> gEglWrapperMap = {
1423 /* EGL_VERSION_1_0 */
1424 { "eglChooseConfig", (EglWrapperFuncPointer)&EglChooseConfigImpl },
1425 { "eglCopyBuffers", (EglWrapperFuncPointer)&EglCopyBuffersImpl },
1426 { "eglCreateContext", (EglWrapperFuncPointer)&EglCreateContextImpl },
1427 { "eglCreatePbufferSurface", (EglWrapperFuncPointer)&EglCreatePbufferSurfaceImpl },
1428 { "eglCreatePixmapSurface", (EglWrapperFuncPointer)&EglCreatePixmapSurfaceImpl },
1429 { "eglCreateWindowSurface", (EglWrapperFuncPointer)&EglCreateWindowSurfaceImpl },
1430 { "eglDestroyContext", (EglWrapperFuncPointer)&EglDestroyContextImpl },
1431 { "eglDestroySurface", (EglWrapperFuncPointer)&EglDestroySurfaceImpl },
1432 { "eglGetConfigAttrib", (EglWrapperFuncPointer)&EglGetConfigAttribImpl },
1433 { "eglGetConfigs", (EglWrapperFuncPointer)&EglGetConfigsImpl },
1434 { "eglGetCurrentDisplay", (EglWrapperFuncPointer)&EglGetCurrentDisplayImpl },
1435 { "eglGetCurrentSurface", (EglWrapperFuncPointer)&EglGetCurrentSurfaceImpl },
1436 { "eglGetDisplay", (EglWrapperFuncPointer)&EglGetDisplayImpl },
1437 { "eglGetError", (EglWrapperFuncPointer)&EglGetErrorImpl },
1438 { "eglGetProcAddress", (EglWrapperFuncPointer)&EglGetProcAddressImpl },
1439 { "eglInitialize", (EglWrapperFuncPointer)&EglInitializeImpl },
1440 { "eglMakeCurrent", (EglWrapperFuncPointer)&EglMakeCurrentImpl },
1441 { "eglQueryContext", (EglWrapperFuncPointer)&EglQueryContextImpl },
1442 { "eglQueryString", (EglWrapperFuncPointer)&EglQueryStringImpl },
1443 { "eglQuerySurface", (EglWrapperFuncPointer)&EglQuerySurfaceImpl },
1444 { "eglSwapBuffers", (EglWrapperFuncPointer)&EglSwapBuffersImpl },
1445 { "eglTerminate", (EglWrapperFuncPointer)&EglTerminateImpl },
1446 { "eglWaitGL", (EglWrapperFuncPointer)&EglWaitGLImpl },
1447 { "eglWaitNative", (EglWrapperFuncPointer)&EglWaitNativeImpl },
1448
1449 /* EGL_VERSION_1_1 */
1450 { "eglBindTexImage", (EglWrapperFuncPointer)&EglBindTexImageImpl },
1451 { "eglReleaseTexImage", (EglWrapperFuncPointer)&EglReleaseTexImageImpl },
1452 { "eglSurfaceAttrib", (EglWrapperFuncPointer)&EglSurfaceAttribImpl },
1453 { "eglSwapInterval", (EglWrapperFuncPointer)&EglSwapIntervalImpl },
1454
1455 /* EGL_VERSION_1_2 */
1456 { "eglBindAPI", (EglWrapperFuncPointer)&EglBindAPIImpl },
1457 { "eglQueryAPI", (EglWrapperFuncPointer)&EglQueryAPIImpl },
1458 { "eglCreatePbufferFromClientBuffer", (EglWrapperFuncPointer)&EglCreatePbufferFromClientBufferImpl },
1459 { "eglReleaseThread", (EglWrapperFuncPointer)&EglReleaseThreadImpl },
1460 { "eglWaitClient", (EglWrapperFuncPointer)&EglWaitClientImpl },
1461
1462 /* EGL_VERSION_1_3 */
1463 /* EGL_VERSION_1_4 */
1464 { "eglGetCurrentContext", (EglWrapperFuncPointer)&EglGetCurrentContextImpl },
1465
1466 /* EGL_VERSION_1_5 */
1467 { "eglCreateSync", (EglWrapperFuncPointer)&EglCreateSyncImpl },
1468 { "eglDestroySync", (EglWrapperFuncPointer)&EglDestroySyncImpl },
1469 { "eglClientWaitSync", (EglWrapperFuncPointer)&EglClientWaitSyncImpl },
1470 { "eglGetSyncAttrib", (EglWrapperFuncPointer)&EglGetSyncAttribImpl },
1471 { "eglCreateImage", (EglWrapperFuncPointer)&EglCreateImageImpl },
1472 { "eglDestroyImage", (EglWrapperFuncPointer)&EglDestroyImageImpl },
1473 { "eglGetPlatformDisplay", (EglWrapperFuncPointer)&EglGetPlatformDisplayImpl },
1474 { "eglCreatePlatformWindowSurface", (EglWrapperFuncPointer)&EglCreatePlatformWindowSurfaceImpl },
1475 { "eglCreatePlatformPixmapSurface", (EglWrapperFuncPointer)&EglCreatePlatformPixmapSurfaceImpl },
1476 { "eglWaitSync", (EglWrapperFuncPointer)&EglWaitSyncImpl },
1477
1478 /* EGL_EXTENTIONS */
1479 { "eglLockSurfaceKHR", (EglWrapperFuncPointer)&EglLockSurfaceKHRImpl },
1480 { "eglUnlockSurfaceKHR", (EglWrapperFuncPointer)&EglUnlockSurfaceKHRImpl },
1481 { "eglDupNativeFenceFDANDROID", (EglWrapperFuncPointer)&EglDupNativeFenceFDANDROIDImpl },
1482
1483 { "eglCreateImageKHR", (EglWrapperFuncPointer)&EglCreateImageKHRImpl },
1484 { "eglDestroyImageKHR", (EglWrapperFuncPointer)&EglDestroyImageKHRImpl },
1485
1486 { "eglCreateSyncKHR", (EglWrapperFuncPointer)&EglCreateSyncKHRImpl },
1487 { "eglDestroySyncKHR", (EglWrapperFuncPointer)&EglDestroySyncKHRImpl },
1488 { "eglClientWaitSyncKHR", (EglWrapperFuncPointer)&EglClientWaitSyncKHRImpl },
1489 { "eglGetSyncAttribKHR", (EglWrapperFuncPointer)&EglGetSyncAttribKHRImpl },
1490
1491 { "eglSignalSyncKHR", (EglWrapperFuncPointer)&EglSignalSyncKHRImpl },
1492
1493 { "eglCreateStreamKHR", (EglWrapperFuncPointer)&EglCreateStreamKHRImpl },
1494 { "eglDestroyStreamKHR", (EglWrapperFuncPointer)&EglDestroyStreamKHRImpl },
1495 { "eglStreamAttribKHR", (EglWrapperFuncPointer)&EglStreamAttribKHRImpl },
1496 { "eglQueryStreamKHR", (EglWrapperFuncPointer)&EglQueryStreamKHRImpl },
1497 { "eglQueryStreamu64KHR", (EglWrapperFuncPointer)&EglQueryStreamu64KHRImpl },
1498
1499 { "eglStreamConsumerGLTextureExternalKHR", (EglWrapperFuncPointer)&EglStreamConsumerGLTextureExternalKHRImpl },
1500 { "eglStreamConsumerAcquireKHR", (EglWrapperFuncPointer)&EglStreamConsumerAcquireKHRImpl },
1501 { "eglStreamConsumerReleaseKHR", (EglWrapperFuncPointer)&EglStreamConsumerReleaseKHRImpl },
1502
1503 { "eglCreateStreamProducerSurfaceKHR", (EglWrapperFuncPointer)&EglCreateStreamProducerSurfaceKHRImpl },
1504
1505 { "eglQueryStreamTimeKHR", (EglWrapperFuncPointer)&EglQueryStreamTimeKHRImpl },
1506
1507 { "eglGetStreamFileDescriptorKHR", (EglWrapperFuncPointer)&EglGetStreamFileDescriptorKHRImpl },
1508 { "eglCreateStreamFromFileDescriptorKHR", (EglWrapperFuncPointer)&EglCreateStreamFromFileDescriptorKHRImpl },
1509
1510 { "eglWaitSyncKHR", (EglWrapperFuncPointer)&EglWaitSyncKHRImpl },
1511
1512 /* EGL_EXT_platform_base */
1513 { "eglGetPlatformDisplayEXT", (EglWrapperFuncPointer)&EglGetPlatformDisplayEXTImpl },
1514 { "eglCreatePlatformWindowSurfaceEXT", (EglWrapperFuncPointer)&EglCreatePlatformWindowSurfaceEXTImpl },
1515 { "eglCreatePlatformPixmapSurfaceEXT", (EglWrapperFuncPointer)&EglCreatePlatformPixmapSurfaceEXTImpl },
1516
1517 { "eglSwapBuffersWithDamageKHR", (EglWrapperFuncPointer)&EglSwapBuffersWithDamageKHRImpl },
1518 { "eglSetDamageRegionKHR", (EglWrapperFuncPointer)&EglSetDamageRegionKHRImpl },
1519
1520 /* EGL_EXT_swap_buffers_with_damage */
1521 { "eglSwapBuffersWithDamageEXT", (EglWrapperFuncPointer)&EglSwapBuffersWithDamageEXTImpl },
1522
1523 { "eglSetBlobCacheFuncsANDROID", (EglWrapperFuncPointer)&EglSetBlobCacheFuncsANDROIDImpl },
1524
1525 /* EGL_ANDROID_get_frame_timestamps */
1526 { "eglGetCompositorTimingSupportedANDROID", (EglWrapperFuncPointer)&EglGetCompositorTimingSupportedANDROIDImpl },
1527 { "eglGetFrameTimestampSupportedANDROID", (EglWrapperFuncPointer)&EglGetFrameTimestampSupportedANDROIDImpl },
1528 { "eglPresentationTimeANDROID", (EglWrapperFuncPointer)&EglPresentationTimeANDROIDImpl },
1529
1530 /* EGL_ANDROID_get_native_client_buffer */
1531 { "eglGetNativeClientBufferANDROID", (EglWrapperFuncPointer)&EglGetNativeClientBufferANDROIDImpl },
1532 };
1533
FindEglWrapperApi(const std::string & name)1534 EglWrapperFuncPointer FindEglWrapperApi(const std::string &name)
1535 {
1536 if (gEglWrapperMap.find(name) != gEglWrapperMap.end()) {
1537 return gEglWrapperMap.at(name);
1538 }
1539
1540 WLOGW("FindEglWrapperApi did not find an entry for %{public}s", name.c_str());
1541 return nullptr;
1542 }
1543
CheckEglWrapperApi(const std::string & name)1544 bool CheckEglWrapperApi(const std::string &name)
1545 {
1546 if (gEglWrapperMap.find(name) != gEglWrapperMap.end()) {
1547 return true;
1548 }
1549 return false;
1550 }
1551 }; // namespace OHOS
1552