Skip to content

Commit 95a29ae

Browse files
author
luozhiming
committed
整理和合并 egl 的代码结构
1 parent dda06a7 commit 95a29ae

30 files changed

+852
-112
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ release.zip
88
release.tar.gz
99
release
1010
.sconsign.dblite
11+
.vscode/*.*

awtk-port/SConscript

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import copy
44
BIN_DIR = os.environ['BIN_DIR'];
55
LIB_DIR = os.environ['LIB_DIR'];
66
env = DefaultEnvironment().Clone()
7-
8-
SOURCES = ['mouse_thread.c', 'input_thread.c', 'input_dispatcher.c', 'lcd_linux_fb.c', 'lcd_linux_drm.c', 'main_loop_linux.c', 'lcd_mem_others.c']
7+
SOURCES = ['mouse_thread.c', 'input_thread.c', 'input_dispatcher.c', 'lcd_linux_fb.c', 'lcd_linux_drm.c', 'main_loop_linux.c', 'lcd_linux_egl.c', 'lcd_mem_others.c' ]
98

109
if os.environ['TSLIB_LIB_DIR']:
1110
SOURCES = ['tslib_thread.c'] + SOURCES;
@@ -14,9 +13,9 @@ env.Library(os.path.join(LIB_DIR, 'awtk_linux_fb'), SOURCES)
1413

1514
env['LIBS'] = ['awtk_linux_fb'] + env['LIBS']
1615

17-
env.Program(os.path.join(BIN_DIR, 'mouse_test'), ["mouse_thread_test.c"])
18-
env.Program(os.path.join(BIN_DIR, 'input_test'), ["input_thread_test.c"])
19-
env.Program(os.path.join(BIN_DIR, 'fb_test'), ["fb_test.c"])
16+
env.Program(os.path.join(BIN_DIR, 'mouse_test'), ["test/mouse_thread_test.c"])
17+
env.Program(os.path.join(BIN_DIR, 'input_test'), ["test/input_thread_test.c"])
18+
env.Program(os.path.join(BIN_DIR, 'fb_test'), ["test/fb_test.c"])
2019

2120
if os.environ['TSLIB_LIB_DIR']:
22-
env.Program(os.path.join(BIN_DIR, 'tslib_test'), ["tslib_thread_test.c"])
21+
env.Program(os.path.join(BIN_DIR, 'tslib_test'), ["test/tslib_thread_test.c"])

awtk-port/egl_devices/egl_devices.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* File: lcd_linux_egl.c
3+
* Author: AWTK Develop Team
4+
* Brief: linux egl lcd
5+
*
6+
* Copyright (c) 2020 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* License file for more details.
12+
*
13+
*/
14+
15+
/**
16+
* History:
17+
* ================================================================
18+
* 2020-11-06 Lou ZhiMing <[email protected]> created
19+
*
20+
*/
21+
22+
#ifndef TK_EGL_DEVICES_H
23+
#define TK_EGL_DEVICES_H
24+
25+
#include "base/types_def.h"
26+
27+
BEGIN_C_DECLS
28+
29+
void* egl_devices_create(const char* filename);
30+
ret_t egl_devices_dispose(void* ctx);
31+
32+
float_t egl_devices_get_ratio(void* ctx);
33+
int32_t egl_devices_get_width(void* ctx);
34+
int32_t egl_devices_get_height(void* ctx);
35+
36+
ret_t egl_devices_make_current(void* ctx);
37+
ret_t egl_devices_swap_buffers(void* ctx);
38+
39+
END_C_DECLS
40+
41+
#endif /*TK_EGL_DEVICES_H*/
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/**
2+
* File: egl_devices.c
3+
* Author: AWTK Develop Team
4+
* Brief: egl devices for fsl
5+
*
6+
* Copyright (c) 2020 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* License file for more details.
12+
*
13+
*/
14+
15+
/**
16+
* History:
17+
* ================================================================
18+
* 2020-11-06 Lou ZhiMing <[email protected]> created
19+
*
20+
*/
21+
22+
#include <GLES2/gl2.h>
23+
#include <GLES2/gl2ext.h>
24+
#include <EGL/egl.h>
25+
#include "fsl_egl.h"
26+
#include "../egl_devices.h"
27+
#include "tkc/mem.h"
28+
29+
typedef struct _egl_devices_fsl_context_t {
30+
EGLint numconfigs;
31+
EGLDisplay egldisplay;
32+
EGLConfig eglconfig;
33+
EGLSurface eglsurface;
34+
EGLContext eglcontext;
35+
EGLNativeWindowType eglNativeWindow;
36+
EGLNativeDisplayType eglNativeDisplayType;
37+
} egl_devices_fsl_context_t;
38+
39+
static const EGLint s_configAttribs[] =
40+
{
41+
EGL_SAMPLES, 0,
42+
EGL_RED_SIZE, 8,
43+
EGL_GREEN_SIZE, 8,
44+
EGL_BLUE_SIZE, 8,
45+
EGL_ALPHA_SIZE, EGL_DONT_CARE,
46+
EGL_STENCIL_SIZE, 8,
47+
EGL_DEPTH_SIZE, 0,
48+
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
49+
EGL_MIN_SWAP_INTERVAL, 1,
50+
EGL_NONE,
51+
};
52+
53+
void* egl_devices_create(const char* filename) {
54+
egl_devices_fsl_context_t* ctx = TKMEM_ZALLOC(egl_devices_fsl_context_t);
55+
return_value_if_fail(ctx != NULL, NULL);
56+
57+
ctx->eglNativeDisplayType = fsl_getNativeDisplay();
58+
ctx->egldisplay = eglGetDisplay(ctx->eglNativeDisplayType);
59+
eglInitialize(ctx->egldisplay, NULL, NULL);
60+
assert(eglGetError() == EGL_SUCCESS);
61+
eglBindAPI(EGL_OPENGL_ES_API);
62+
63+
eglChooseConfig(ctx->egldisplay, s_configAttribs, &(ctx->eglconfig), 1, &(ctx->numconfigs));
64+
assert(eglGetError() == EGL_SUCCESS);
65+
assert(ctx->numconfigs == 1);
66+
67+
ctx->eglNativeWindow = fsl_createwindow(ctx->egldisplay, ctx->eglNativeDisplayType, filename);
68+
assert(ctx->eglNativeWindow);
69+
70+
ctx->eglsurface = eglCreateWindowSurface(ctx->egldisplay, ctx->eglconfig, ctx->eglNativeWindow, NULL);
71+
72+
assert(eglGetError() == EGL_SUCCESS);
73+
EGLint ContextAttribList[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
74+
ctx->eglcontext = eglCreateContext(ctx->egldisplay, ctx->eglconfig, EGL_NO_CONTEXT, ContextAttribList );
75+
assert(eglGetError() == EGL_SUCCESS);
76+
eglMakeCurrent(ctx->egldisplay, ctx->eglsurface, ctx->eglsurface, ctx->eglcontext);
77+
assert(eglGetError() == EGL_SUCCESS);
78+
79+
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
80+
81+
glDisable(GL_DEPTH_TEST);
82+
glDisable(GL_SCISSOR_TEST);
83+
84+
eglSwapInterval(ctx->egldisplay, 1);
85+
assert(eglGetError() == EGL_SUCCESS);
86+
87+
return (void*)ctx;
88+
}
89+
90+
ret_t egl_devices_dispose(void* ctx) {
91+
egl_devices_fsl_context_t* context = (egl_devices_fsl_context_t*)ctx;
92+
return_value_if_fail(context != NULL, RET_BAD_PARAMS);
93+
94+
eglMakeCurrent(context->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
95+
assert(eglGetError() == EGL_SUCCESS);
96+
eglTerminate(context->egldisplay);
97+
assert(eglGetError() == EGL_SUCCESS);
98+
eglReleaseThread();
99+
100+
return RET_OK;
101+
}
102+
103+
float_t egl_devices_get_ratio(void* ctx) {
104+
(void)ctx;
105+
return 1.0f;
106+
}
107+
108+
int32_t egl_devices_get_width(void* ctx) {
109+
EGLint width = 0;
110+
egl_devices_fsl_context_t* context = (egl_devices_fsl_context_t*)ctx;
111+
return_value_if_fail(context != NULL, RET_BAD_PARAMS);
112+
113+
eglQuerySurface(context->egldisplay, context->eglsurface, EGL_WIDTH, &width);
114+
return (int32_t)width;
115+
}
116+
117+
int32_t egl_devices_get_height(void* ctx) {
118+
EGLint height = 0;
119+
egl_devices_fsl_context_t* context = (egl_devices_fsl_context_t*)ctx;
120+
return_value_if_fail(context != NULL, RET_BAD_PARAMS);
121+
122+
eglQuerySurface(context->egldisplay, context->eglsurface, EGL_HEIGHT, &height);
123+
return (int32_t)height;
124+
}
125+
126+
ret_t egl_devices_make_current(void* ctx) {
127+
egl_devices_fsl_context_t* context = (egl_devices_fsl_context_t*)ctx;
128+
return_value_if_fail(context != NULL, RET_BAD_PARAMS);
129+
130+
eglMakeCurrent(context->egldisplay, context->eglsurface, ctx->eglsurface, ctx->eglcontext);
131+
return eglGetError() == EGL_SUCCESS ? RET_OK : RET_FAIL;
132+
}
133+
134+
ret_t egl_devices_swap_buffers(void* ctx) {
135+
egl_devices_fsl_context_t* context = (egl_devices_fsl_context_t*)ctx;
136+
return_value_if_fail(context != NULL, RET_BAD_PARAMS);
137+
138+
eglSwapBuffers(context->egldisplay, context->eglsurface);
139+
return eglGetError() == EGL_SUCCESS ? RET_OK : RET_FAIL;
140+
}

awtk-port/egl_devices/fsl/fsl_egl.c

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/****************************************************************************
2+
* Copyright (c) 2012 Freescale Semiconductor, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
*
11+
* * Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* * Neither the name of the Freescale Semiconductor, Inc. nor the names of
16+
* its contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+
Labels parameters
31+
32+
*****************************************************************************/
33+
34+
#include <stdio.h>
35+
#include <stdlib.h>
36+
#include <fcntl.h>
37+
#include <assert.h>
38+
#include <string.h>
39+
#include <EGL/egl.h>
40+
41+
#ifdef EGL_USE_X11
42+
#include <X11/X.h>
43+
#include <X11/Xlib.h>
44+
#endif
45+
46+
EGLNativeDisplayType fsl_getNativeDisplay()
47+
{
48+
EGLNativeDisplayType eglNativeDisplayType = NULL;
49+
#if (defined EGL_USE_X11)
50+
eglNativeDisplayType = XOpenDisplay(NULL);
51+
assert(eglNativeDisplayType != NULL);
52+
#elif (defined EGL_API_FB)
53+
eglNativeDisplayType = fbGetDisplayByIndex(0); //Pass the argument as required to show the framebuffer
54+
#else
55+
display = EGL_DEFAULT_DISPLAY;
56+
#endif
57+
return eglNativeDisplayType;
58+
}
59+
60+
EGLNativeWindowType fsl_createwindow(EGLDisplay egldisplay, EGLNativeDisplayType eglNativeDisplayType, const char* filename)
61+
{
62+
EGLNativeWindowType native_window = (EGLNativeWindowType)0;
63+
64+
#if (defined EGL_USE_X11)
65+
Window window, rootwindow;
66+
int screen = DefaultScreen(eglNativeDisplayType);
67+
rootwindow = RootWindow(eglNativeDisplayType,screen);
68+
window = XCreateSimpleWindow(eglNativeDisplayType, rootwindow, 0, 0, 400, 533, 0, 0, WhitePixel (eglNativeDisplayType, screen));
69+
XMapWindow(eglNativeDisplayType, window);
70+
native_window = window;
71+
#else
72+
const char *vendor = eglQueryString(egldisplay, EGL_VENDOR);
73+
printf("vendor:%s \r\n", vendor);
74+
if (strstr(vendor, "Imagination Technologies"))
75+
native_window = (EGLNativeWindowType)0;
76+
else if (strstr(vendor, "AMD"))
77+
native_window = (EGLNativeWindowType) open(filename, O_RDWR);
78+
else if (strstr(vendor, "Vivante")) //NEEDS FIX - functs don't exist on other platforms
79+
{
80+
#if (defined EGL_API_FB)
81+
native_window = fbCreateWindow(eglNativeDisplayType, 0, 0, 0, 0);
82+
#endif
83+
}
84+
else
85+
{
86+
printf("Unknown vendor [%s]\n", vendor);
87+
return 0;
88+
}
89+
#endif
90+
return native_window;
91+
92+
}
93+
94+
95+
void fsl_destroywindow(EGLNativeWindowType eglNativeWindowType, EGLNativeDisplayType eglNativeDisplayType)
96+
{
97+
(void) eglNativeWindowType;
98+
#if (defined EGL_USE_X11)
99+
//close x display
100+
XCloseDisplay(eglNativeDisplayType);
101+
#endif
102+
}

awtk-port/egl_devices/fsl/fsl_egl.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/****************************************************************************
2+
* Copyright (c) 2012 Freescale Semiconductor, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
*
11+
* * Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* * Neither the name of the Freescale Semiconductor, Inc. nor the names of
16+
* its contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+
Labels parameters
31+
32+
*****************************************************************************/
33+
34+
#ifndef _FSL_EGL_H_
35+
#define _FSL_EGL_H_
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
39+
#include <EGL/egl.h>
40+
41+
EGLNativeDisplayType fsl_getNativeDisplay();
42+
EGLNativeWindowType fsl_createwindow(EGLDisplay egldisplay, EGLNativeDisplayType eglNativeDisplayType, const char* filename);
43+
void fsl_destroywindow(EGLNativeWindowType eglNativeWindowType,EGLNativeDisplayType eglNativeDisplayType);
44+
45+
46+
#ifdef __cplusplus
47+
}
48+
#endif
49+
#endif //_FSL_EGL_H_
50+

0 commit comments

Comments
 (0)