基于开源mesa3d的GPU驱动,OpenHarmony-4.x版本图形适配要点 原创
前言
OpenHarmony-4.0-Beta1版本已经发布有一段时间,大家伙都体验到了,也有很多开发者开始适配OpenHarmony-4.x版本,相信也会或多或少遇到一些问题,其中就有图形相关的适配。
本文仅针对一种情况的适配问题给出参考解决方案。
问题现象
适配OpenHarmony-4.x版本后,图形没有正常显示,调试发现render_service不能正常启动,出错日志如下:
出现以上问题,大概率是基于开源mesa3d驱动才会有这样的问题
解决方案
调用eglGetProcAddress可以解决该问题。
函数具体功能描述如下:
eglGetProcAddress returns the address of the client API or EGL function named by procname. procname must be a null-terminated string. The pointer returned should be cast to a function pointer matching the function’s definition in the corresponding API or extension specification. A return value of NULL indicates that the specific function does not exist for the implementation.
A non-NULL return value does not guarantee that an extension function is actually supported at runtime. The client must also make a corresponding query, such as glGetString(GL_EXTENSIONS) for OpenGL and OpenGL ES extensions; vgGetString(VG_EXTENSIONS) for OpenVG extensions; eglQueryString(display, EGL_EXTENSIONS); or query the EGL or client API version for non-extension functions, to determine if a function is supported by EGL or a specific client API context.
Client API function pointers returned by eglGetProcAddress are independent of the display and the currently bound client API context, and may be used by any client API context which supports the function.
eglGetProcAddress may be queried for all EGL and client API functions supported by the implementation (whether those functions are extensions or not, and whether they are supported by the current client API context or not).
For functions that are queryable with eglGetProcAddress, implementations may choose to also export those functions statically from the object libraries implementing those functions. However, portable clients cannot rely on this behavior.
Khronos官方参考:https://registry.khronos.org/EGL/sdk/docs/man/html/eglGetProcAddress.xhtml
具体修改
涉及的文件修改如下(以OpenHarmony-4.0-Release分支的代码为例):
修改的内容参考如下:
1. BUILD.gn修改
增加宏控制(这里以本人适配的一加6T为例,其他,如树莓派等采用mesa3d开源驱动的可参考如下,根据自己的产品型号具体修改)
2. CPP源码修改
以rs_sub_thread.cpp修改为例(其他CPP参考修改即可)
参考代码:
// Mesa3D
#ifdef SDM845
static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
static PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR = (PFNEGLCREATESYNCKHRPROC)eglGetProcAddress("eglCreateSyncKHR");
static PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR = (PFNEGLDESTROYSYNCKHRPROC)eglGetProcAddress("eglDestroySyncKHR");
static PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR = (PFNEGLCLIENTWAITSYNCKHRPROC)eglGetProcAddress("eglClientWaitSyncKHR");
static PFNEGLWAITSYNCKHRPROC eglWaitSyncKHR = (PFNEGLWAITSYNCKHRPROC)eglGetProcAddress("eglWaitSyncKHR");
static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR");
static PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR");
#endif
其中rs_image.cpp需添加头文件,参考如下:
--- a/rosen/modules/render_service_base/src/render/rs_image.cpp
+++ b/rosen/modules/render_service_base/src/render/rs_image.cpp
@@ -32,9 +32,36 @@
#include "rs_trace.h"
#include "sandbox_utils.h"
+#ifdef SDM845
+#ifdef ROSEN_OHOS
+#include "EGL/egl.h"
+#include "EGL/eglext.h"
+#include "GLES2/gl2.h"
+#include "GLES2/gl2ext.h"
+
+#include "external_window.h"
+#include "surface_buffer.h"
+#include "window.h"
+#endif
+#endif
不错不错,挺好!!
感谢分享