基于开源mesa3d的GPU驱动,OpenHarmony-4.x版本图形适配要点 原创

AlgoIdeas
发布于 2023-9-16 22:39
浏览
0收藏

前言

OpenHarmony-4.0-Beta1版本已经发布有一段时间,大家伙都体验到了,也有很多开发者开始适配OpenHarmony-4.x版本,相信也会或多或少遇到一些问题,其中就有图形相关的适配。
本文仅针对一种情况的适配问题给出参考解决方案。

问题现象

适配OpenHarmony-4.x版本后,图形没有正常显示,调试发现render_service不能正常启动,出错日志如下:
基于开源mesa3d的GPU驱动,OpenHarmony-4.x版本图形适配要点-鸿蒙开发者社区

出现以上问题,大概率是基于开源mesa3d驱动才会有这样的问题

解决方案

调用eglGetProcAddress可以解决该问题。

基于开源mesa3d的GPU驱动,OpenHarmony-4.x版本图形适配要点-鸿蒙开发者社区

函数具体功能描述如下:

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分支的代码为例):

基于开源mesa3d的GPU驱动,OpenHarmony-4.x版本图形适配要点-鸿蒙开发者社区

修改的内容参考如下:

1. BUILD.gn修改

增加宏控制(这里以本人适配的一加6T为例,其他,如树莓派等采用mesa3d开源驱动的可参考如下,根据自己的产品型号具体修改)

基于开源mesa3d的GPU驱动,OpenHarmony-4.x版本图形适配要点-鸿蒙开发者社区

2. CPP源码修改

以rs_sub_thread.cpp修改为例(其他CPP参考修改即可)

基于开源mesa3d的GPU驱动,OpenHarmony-4.x版本图形适配要点-鸿蒙开发者社区

参考代码:

// 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

视频演示

https://www.bilibili.com/video/BV1Fu4y1r7pH

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2023-9-16 22:55:48修改
4
收藏
回复
举报
2条回复
按时间正序
/
按时间倒序
物联风景
物联风景

不错不错,挺好!!

1
回复
2023-9-22 09:24:11
忙忙忙困困困
忙忙忙困困困

感谢分享

回复
2024-2-13 22:50:24
回复
    相关推荐