wayland(xdg_wm_base) + egl + opengles——dma_buf 作为纹理数据源(五)_opengles dma-buf(1)

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

文章目录

前言

`本文主要描述如何在一个wayland client 中将一个 dma_buf import 作为一个 opengles texture 数据源
软硬件环境
硬件:aarch64
软件:linux5.10 opengles2.0/3.0 egl1.5


一、EGL dma_buf import 相关的数据结构和函数

如下图所示,EGL 中 import dma_buf 作为 opengles texture ,主要是使用数据结构EGLImageKHR,函数eglCreateImageKHR()和glEGLImageTargetTexture2DOES()
在这里插入图片描述

1. EGLImageKHR

EGLImageKHR 是 EGL (嵌入式系统图形库) 扩展 API 中的一种数据类型。它表示一个 EGL 图像对象的句柄,可用于在不同的图形 API 或上下文之间共享图像数据。 EGLImageKHR 对象通常使用 eglCreateImageKHR 函数创建。这个函数接受诸如 EGL 显示、客户端 API 类型(例如,用于 OpenGL 纹理的 EGL _ GL _ TEXTURE _ 2D _ KHR)和客户端 API 图像源代码句柄等参数。它返回一个 EGLImageKHR 句柄,该句柄以可共享的格式表示图像数据。一旦有了 EGLImageKHR 句柄,就可以将其与其他 EGL 或图形 API 函数一起使用,以便对图像数据执行操作。例如,您可以使用 glEGLImageTargetTexture2DOES 功能将 EGLImageKHR 绑定到 OpenGL 中的纹理对象。 EGLImageKHR 是对核心 EGL 规范的扩展,其可用性和使用可能会根据您正在使用的平台和版本而有所不同。

2. eglCreateImageKHR()

eglCreateImageKHR 函数是 EGL 扩展 API 的一部分,它代表“嵌入式系统图形库”此函数用于从现有的客户端 API 映像源创建 EGLImage。EGLImage 可以被看作是一个句柄,它引用图像数据的格式可以在不同的图形 API 之间共享。

3. glEGLImageTargetTexture2DOES()

函数 glEGLImageTargetTexture2DOES 是 OpenGL ES 中的一个扩展函数,它允许您将 EGLImage 绑定为纹理目标。它将一个 EGLImage 与 OpenGLES 中的纹理对象关联起来,使您能够使用 EGLImage 作为纹理数据源。

二、egl 中 import dma_buf 作为纹理的代码实例

1. egl_wayland_dmabuf_texture 代码实例

本实例是以 /dev/dma_heap/linux,cma 节点作为dmabuf export ,得到dma_fd
在这里插入图片描述

1.1 基于opengles2.0 相关接口的egl_wayland_dmabuf_texture2_0.c
#include <wayland-client.h>
#include <wayland-server.h>
#include <wayland-egl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <linux/dma-heap.h>
#include <linux/dma-buf.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <drm/drm\_fourcc.h>
#include "xdg-shell-client-protocol.h"

#define WIDTH 800
#define HEIGHT 600

struct wl\_display \*display = NULL;
struct wl\_compositor \*compositor = NULL;
struct xdg\_wm\_base \*wm_base = NULL;
struct wl\_registry \*registry = NULL;
GLuint texture;
GLint textureLocation;

PFNEGLCREATEIMAGEKHRPROC create_image;
PFNEGLDESTROYIMAGEKHRPROC destroy_image;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;

struct window {
 
	struct wl\_surface \*surface;
    struct xdg\_surface \*xdg_surface;
	struct xdg\_toplevel \*xdg_toplevel;
	struct wl\_egl\_window \*egl_window;
};

// Index to bind the attributes to vertex shaders
const unsigned int VertexArray = 0;

static void
xdg\_wm\_base\_ping(void \*data, struct xdg\_wm\_base \*shell, uint32\_t serial)
{
 
	xdg\_wm\_base\_pong(shell, serial);
}

/\*for xdg\_wm\_base listener\*/
static const struct xdg\_wm\_base\_listener wm_base_listener = {
 
	xdg_wm_base_ping,
};

/\*for registry listener\*/
static void registry\_add\_object(void \*data, struct wl\_registry \*registry, uint32\_t name, const char \*interface, uint32\_t version) 
{
 
    if (!strcmp(interface, "wl\_compositor")) {
 
        compositor = wl\_registry\_bind(registry, name, &wl_compositor_interface, 1);
    } else if (strcmp(interface, "xdg\_wm\_base") == 0) {
 
        wm_base = wl\_registry\_bind(registry, name,
            &xdg_wm_base_interface, 1);
        xdg\_wm\_base\_add\_listener(wm_base, &wm_base_listener, NULL);
    }
}

void registry\_remove\_object(void \*data, struct wl\_registry \*registry, uint32\_t name) 
{
 

}

static struct wl\_registry\_listener registry_listener = {
 registry_add_object, registry_remove_object};

static void
handle\_surface\_configure(void \*data, struct xdg\_surface \*surface,
			 uint32\_t serial)
{
 
	//struct window \*window = data;

	xdg\_surface\_ack\_configure(surface, serial);

	//window->wait\_for\_configure = false;
}

static const struct xdg\_surface\_listener xdg_surface_listener = {
 
	handle_surface_configure
};

static void
handle\_toplevel\_configure(void \*data, struct xdg\_toplevel \*toplevel,
			  int32\_t width, int32\_t height,
			  struct wl\_array \*states)
{
 
}

static void
handle\_toplevel\_close(void \*data, struct xdg\_toplevel \*xdg_toplevel)
{
 
}

static const struct xdg\_toplevel\_listener xdg_toplevel_listener = {
 
	handle_toplevel_configure,
	handle_toplevel_close,
};


bool initWaylandConnection()
{
 	
	if ((display = wl\_display\_connect(NULL)) == NULL)
	{
 
		printf("Failed to connect to Wayland display!\n");
		return false;
	}

	if ((registry = wl\_display\_get\_registry(display)) == NULL)
	{


![img](https://img-blog.csdnimg.cn/img_convert/ef2c5ca61f0efba8bc668b20606b474d.png)
![img](https://img-blog.csdnimg.cn/img_convert/76aed3381b697ca86c5a6c97ac73f08d.png)
![img](https://img-blog.csdnimg.cn/img_convert/9b0facf8559aed691de4a5fd462d8089.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**


**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**

  • 26
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值