Skip to content

Commit 29d6bc7

Browse files
committed
Initial commit
0 parents  commit 29d6bc7

11 files changed

+1130
-0
lines changed

Diff for: .gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.deps/
2+
isolate_snapshot_data
3+
isolate_snapshot_instr
4+
*.so
5+
snapshot.d
6+
vm_snapshot_data
7+
vm_snapshot_instr
8+
config.status
9+
config.log
10+
configure
11+
aclocal.m4
12+
*.o
13+
run_engine
14+
project/
15+
autom4te.cache
16+
build-aux
17+
Makefile
18+
Makefile.in
19+
icudtl.dat
20+

Diff for: Makefile.am

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
bin_PROGRAMS = run_engine
2+
3+
run_engine_LDADD = \
4+
$(DRM_LIBS) \
5+
$(GBM_LIBS) \
6+
$(EGL_LIBS) \
7+
$(GLES2_LIBS) \
8+
-lm \
9+
-lflutter_engine
10+
11+
run_engine_CFLAGS = \
12+
-O2 -g \
13+
-Wall -Wextra \
14+
-std=c99 \
15+
$(DRM_CFLAGS) \
16+
$(GBM_CFLAGS) \
17+
$(EGL_CFLAGS) \
18+
$(GLES2_CFLAGS)
19+
20+
run_engine_SOURCES = \
21+
common.c \
22+
common.h \
23+
drm-common.c \
24+
drm-common.h \
25+
drm-legacy.c \
26+
main.c

Diff for: autogen.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#! /bin/sh
2+
3+
srcdir=`dirname "$0"`
4+
test -z "$srcdir" && srcdir=.
5+
6+
ORIGDIR=`pwd`
7+
cd "$srcdir"
8+
9+
autoreconf --force --verbose --install || exit 1
10+
cd "$ORIGDIR" || exit $?
11+
12+
if test -z "$NOCONFIGURE"; then
13+
exec "$srcdir"/configure "$@"
14+
fi

Diff for: common.c

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#include <errno.h>
2+
#include <fcntl.h>
3+
#include <stdbool.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
8+
#include "common.h"
9+
10+
static struct gbm gbm;
11+
static struct egl egl;
12+
13+
const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier)
14+
{
15+
gbm.dev = gbm_create_device(drm_fd);
16+
17+
if (modifier != DRM_FORMAT_MOD_INVALID) {
18+
fprintf(stderr, "Modifiers requested but support isn't available\n");
19+
return NULL;
20+
}
21+
gbm.surface = gbm_surface_create(gbm.dev, w, h, GBM_FORMAT_XRGB8888,
22+
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
23+
24+
if (!gbm.surface) {
25+
printf("failed to create gbm surface\n");
26+
return NULL;
27+
}
28+
29+
gbm.width = w;
30+
gbm.height = h;
31+
32+
return &gbm;
33+
}
34+
35+
static bool has_ext(const char *extension_list, const char *ext)
36+
{
37+
const char *ptr = extension_list;
38+
int len = strlen(ext);
39+
40+
if (ptr == NULL || *ptr == '\0')
41+
return false;
42+
43+
while (true) {
44+
ptr = strstr(ptr, ext);
45+
if (!ptr)
46+
return false;
47+
48+
if (ptr[len] == ' ' || ptr[len] == '\0')
49+
return true;
50+
51+
ptr += len;
52+
}
53+
}
54+
55+
struct egl* egl_init(const struct gbm *gbm)
56+
{
57+
EGLint major, minor, n;
58+
59+
static const EGLint context_attribs[] = {
60+
EGL_CONTEXT_CLIENT_VERSION, 2,
61+
EGL_NONE
62+
};
63+
64+
static const EGLint config_attribs[] = {
65+
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
66+
EGL_RED_SIZE, 1,
67+
EGL_GREEN_SIZE, 1,
68+
EGL_BLUE_SIZE, 1,
69+
EGL_ALPHA_SIZE, 0,
70+
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
71+
EGL_NONE
72+
};
73+
const char *egl_exts_client, *egl_exts_dpy, *gl_exts;
74+
75+
#define get_proc_client(ext, name) do { \
76+
if (has_ext(egl_exts_client, #ext)) \
77+
egl.name = (void *)eglGetProcAddress(#name); \
78+
} while (0)
79+
#define get_proc_dpy(ext, name) do { \
80+
if (has_ext(egl_exts_dpy, #ext)) \
81+
egl.name = (void *)eglGetProcAddress(#name); \
82+
} while (0)
83+
84+
#define get_proc_gl(ext, name) do { \
85+
if (has_ext(gl_exts, #ext)) \
86+
egl.name = (void *)eglGetProcAddress(#name); \
87+
} while (0)
88+
89+
egl_exts_client = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
90+
get_proc_client(EGL_EXT_platform_base, eglGetPlatformDisplayEXT);
91+
92+
if (egl.eglGetPlatformDisplayEXT) {
93+
egl.display = egl.eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR,
94+
gbm->dev, NULL);
95+
} else {
96+
egl.display = eglGetDisplay((void *)gbm->dev);
97+
}
98+
99+
if (!eglInitialize(egl.display, &major, &minor)) {
100+
printf("failed to initialize\n");
101+
return NULL;
102+
}
103+
104+
egl_exts_dpy = eglQueryString(egl.display, EGL_EXTENSIONS);
105+
get_proc_dpy(EGL_KHR_image_base, eglCreateImageKHR);
106+
get_proc_dpy(EGL_KHR_image_base, eglDestroyImageKHR);
107+
get_proc_dpy(EGL_KHR_fence_sync, eglCreateSyncKHR);
108+
get_proc_dpy(EGL_KHR_fence_sync, eglDestroySyncKHR);
109+
get_proc_dpy(EGL_KHR_fence_sync, eglWaitSyncKHR);
110+
get_proc_dpy(EGL_KHR_fence_sync, eglClientWaitSyncKHR);
111+
printf("Using display %p with EGL version %d.%d\n",
112+
egl.display, major, minor);
113+
114+
printf("===================================\n");
115+
printf("EGL information:\n");
116+
printf(" version: \"%s\"\n", eglQueryString(egl.display, EGL_VERSION));
117+
printf(" vendor: \"%s\"\n", eglQueryString(egl.display, EGL_VENDOR));
118+
printf(" client extensions: \"%s\"\n", egl_exts_client);
119+
printf(" display extensions: \"%s\"\n", egl_exts_dpy);
120+
printf("===================================\n");
121+
122+
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
123+
printf("failed to bind api EGL_OPENGL_ES_API\n");
124+
return NULL;
125+
}
126+
127+
if (!eglChooseConfig(egl.display, config_attribs, &egl.config, 1, &n) || n != 1) {
128+
printf("failed to choose config: %d\n", n);
129+
return NULL;
130+
}
131+
132+
egl.context = eglCreateContext(egl.display, egl.config,
133+
EGL_NO_CONTEXT, context_attribs);
134+
if (egl.context == NULL) {
135+
printf("failed to create context\n");
136+
return NULL;
137+
}
138+
139+
egl.surface = eglCreateWindowSurface(egl.display, egl.config,
140+
(EGLNativeWindowType)gbm->surface, NULL);
141+
if (egl.surface == EGL_NO_SURFACE) {
142+
printf("failed to create egl surface\n");
143+
return NULL;
144+
}
145+
146+
/* connect the context to the surface */
147+
eglMakeCurrent(egl.display, egl.surface, egl.surface, egl.context);
148+
149+
gl_exts = (char *) glGetString(GL_EXTENSIONS);
150+
printf("OpenGL ES 2.x information:\n");
151+
printf(" version: \"%s\"\n", glGetString(GL_VERSION));
152+
printf(" shading language version: \"%s\"\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
153+
printf(" vendor: \"%s\"\n", glGetString(GL_VENDOR));
154+
printf(" renderer: \"%s\"\n", glGetString(GL_RENDERER));
155+
printf(" extensions: \"%s\"\n", gl_exts);
156+
printf("===================================\n");
157+
158+
get_proc_gl(GL_OES_EGL_image, glEGLImageTargetTexture2DOES);
159+
160+
return &egl;
161+
}

Diff for: common.h

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#ifndef _COMMON_H
2+
#define _COMMON_H
3+
4+
#include <GLES2/gl2.h>
5+
#include <GLES2/gl2ext.h>
6+
#include <EGL/egl.h>
7+
#include <EGL/eglext.h>
8+
9+
#include <gbm.h>
10+
#include <drm_fourcc.h>
11+
12+
#ifndef DRM_FORMAT_MOD_LINEAR
13+
#define DRM_FORMAT_MOD_LINEAR 0
14+
#endif
15+
16+
#ifndef DRM_FORMAT_MOD_INVALID
17+
#define DRM_FORMAT_MOD_INVALID ((((__u64)0) << 56) | ((1ULL << 56) - 1))
18+
#endif
19+
20+
#ifndef EGL_KHR_platform_gbm
21+
#define EGL_KHR_platform_gbm 1
22+
#define EGL_PLATFORM_GBM_KHR 0x31D7
23+
#endif /* EGL_KHR_platform_gbm */
24+
25+
#ifndef EGL_EXT_platform_base
26+
#define EGL_EXT_platform_base 1
27+
typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, void *native_display, const EGLint *attrib_list);
28+
typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
29+
typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
30+
#ifdef EGL_EGLEXT_PROTOTYPES
31+
EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT (EGLenum platform, void *native_display, const EGLint *attrib_list);
32+
EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
33+
EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
34+
#endif
35+
#endif /* EGL_EXT_platform_base */
36+
37+
struct gbm {
38+
struct gbm_device *dev;
39+
struct gbm_surface *surface;
40+
int width, height;
41+
};
42+
43+
const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier);
44+
45+
struct egl {
46+
EGLDisplay display;
47+
EGLConfig config;
48+
EGLContext context;
49+
EGLSurface surface;
50+
51+
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
52+
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
53+
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
54+
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
55+
PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR;
56+
PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR;
57+
PFNEGLWAITSYNCKHRPROC eglWaitSyncKHR;
58+
PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR;
59+
PFNEGLDUPNATIVEFENCEFDANDROIDPROC eglDupNativeFenceFDANDROID;
60+
61+
void (*draw)(unsigned i);
62+
};
63+
64+
static inline int __egl_check(void *ptr, const char *name)
65+
{
66+
if (!ptr) {
67+
printf("no %s\n", name);
68+
return -1;
69+
}
70+
return 0;
71+
}
72+
73+
#define egl_check(egl, name) __egl_check((egl)->name, #name)
74+
75+
struct egl* egl_init(const struct gbm *gbm);
76+
77+
#endif /* _COMMON_H */

Diff for: configure.ac

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
AC_PREREQ([2.60])
2+
AC_INIT([run_engine], [0.0.1])
3+
AC_CONFIG_AUX_DIR([build-aux])
4+
5+
# Initialize Automake
6+
AM_INIT_AUTOMAKE([foreign dist-bzip2])
7+
8+
AC_PROG_CC
9+
10+
# Enable quiet compiles on automake 1.11.
11+
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
12+
13+
# Obtain compiler/linker options for depedencies
14+
PKG_CHECK_MODULES(DRM, [libdrm >= 2.4.71])
15+
PKG_CHECK_MODULES(GBM, gbm >= 13.0)
16+
PKG_CHECK_MODULES(EGL, egl)
17+
PKG_CHECK_MODULES(GLES2, glesv2)
18+
19+
AC_CHECK_LIB([gbm], [gbm_bo_get_modifier], [gbm_modifiers=yes], [])
20+
21+
AC_CONFIG_FILES([Makefile])
22+
AC_OUTPUT

0 commit comments

Comments
 (0)