mesa-demos: add more examples

Issue #2507.
This commit is contained in:
Sebastian Sumpf 2017-08-17 18:19:17 +02:00 committed by Christian Helmuth
parent dbeb7410f8
commit 89cb3aa238
13 changed files with 405 additions and 204 deletions

View File

@ -1,152 +0,0 @@
set build_components {
core init
drivers/timer
drivers/input
drivers/framebuffer
lib/mesa/swrast
server/nitpicker
server/nit_fb
app/launchpad
app/pointer
test/mesa_demo/eglgears
}
source ${genode_dir}/repos/base/run/platform_drv.inc
append_platform_drv_build_components
build $build_components
create_boot_directory
set config {
<config prio_levels="2">
<parent-provides>
<service name="CPU"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="LOG"/>
<service name="PD"/>
<service name="RM"/>
<service name="ROM"/>
</parent-provides>
<default caps="100"/>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
}
append_if [have_spec linux] config {
<start name="fb_sdl" caps="200">
<resource name="RAM" quantum="4M"/>
<provides>
<service name="Input"/>
<service name="Framebuffer"/>
</provides>
</start>}
append_platform_drv_config
append_if [expr ![have_spec linux]] config {
<start name="fb_drv">
<resource name="RAM" quantum="10M"/>
<provides>
<service name="Framebuffer"/>
</provides>
<route><any-service> <parent /> <any-child/> </any-service> </route>
</start>}
append_if [have_spec ps2] config {
<start name="ps2_drv">
<resource name="RAM" quantum="2M"/>
<provides> <service name="Input"/> </provides>
</start> }
append config {
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
</start>
<start name="nitpicker">
<resource name="RAM" quantum="1M"/>
<provides><service name="Nitpicker"/></provides>
<config>
<domain name="pointer" layer="1" content="client" label="no" origin="pointer" />
<domain name="default" layer="2" content="client" focus="click" hover="always" />
<policy label_prefix="pointer" domain="pointer"/>
<default-policy domain="default"/>
</config>
<route><any-service><parent/><any-child/></any-service></route>
</start>
<start name="pointer">
<resource name="RAM" quantum="1M"/>
</start>
<start name="launchpad" caps="400">
<resource name="RAM" quantum="128M"/>
<config>
<launcher name="init" ram_quota="100M" caps="300">
<config>
<parent-provides>
<service name="ROM"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
<service name="Platform"/>
<service name="Nitpicker"/>
<service name="Timer"/>
<service name="Drm" />
</parent-provides>
<default caps="100"/>
<start name="nit_fb">
<resource name="RAM" quantum="2M"/>
<provides><service name="Input"/><service name="Framebuffer"/></provides>
<route><any-service><parent/></any-service></route>
<config xpos="300" ypos="100" width="600" height="600" />
</start>
<start name="gears" caps="128">
<resource name="RAM" quantum="1G"/>
<route>
<service name="ROM" label="egl_drv.lib.so"> <parent label="egl_swrast.lib.so" /> </service>
<any-service> <parent /> <any-child/> </any-service>
</route>
<config>
<vfs>
<dir name="dev"> <log/> </dir>
</vfs>
<libc stdout="/dev/log"/>
</config>
</start>
</config>
</launcher>
</config>
</start>
</config>
}
install_config $config
set boot_modules {
core init ld.lib.so timer nitpicker nit_fb
launchpad gears pointer
libc.lib.so libm.lib.so pthread.lib.so
egl.lib.so mesa.lib.so stdcxx.lib.so
expat.lib.so glapi.lib.so
egl_swrast.lib.so
}
lappend_if [have_spec linux] boot_modules fb_sdl
lappend_if [expr ![have_spec linux]] boot_modules fb_drv
lappend_if [have_spec ps2] boot_modules ps2_drv
append_platform_drv_boot_modules
build_boot_image $boot_modules
append qemu_args " -m 768"
run_genode_until forever

View File

@ -0,0 +1,18 @@
set demo_component test/mesa_demo/gears
set demo_binary gears
set demo_ram_quota 32M
set demo_caps 200
set demo_config {
<config ld_verbose="true">
<libc stdout="/dev/log" stderr="/dev/log"/>
<vfs>
<dir name="dev"> <log/> </dir>
</vfs>
</config>}
set demo_modules {
gears
}
source ${genode_dir}/repos/libports/run/mesa.inc

View File

@ -0,0 +1,2 @@
set use_i965 0
source ${genode_dir}/repos/libports/run/mesa-gears.inc

View File

@ -0,0 +1,2 @@
set use_i965 1
source ${genode_dir}/repos/libports/run/mesa-gears.inc

View File

@ -0,0 +1,18 @@
set demo_component test/mesa_demo/triangle_gl
set demo_binary triangle_gl
set demo_ram_quota 32M
set demo_caps 200
set demo_config {
<config ld_verbose="true">
<libc stdout="/dev/log" stderr="/dev/log"/>
<vfs>
<dir name="dev"> <log/> </dir>
</vfs>
</config>}
set demo_modules {
triangle_gl
}
source ${genode_dir}/repos/libports/run/mesa.inc

View File

@ -0,0 +1,2 @@
set use_i965 0
source ${genode_dir}/repos/libports/run/mesa-triangle_gl.inc

View File

@ -0,0 +1,2 @@
set use_i965 1
source ${genode_dir}/repos/libports/run/mesa-triangle_gl.inc

206
repos/libports/run/mesa.inc Normal file
View File

@ -0,0 +1,206 @@
if {[have_spec linux] && $use_i965} {
puts "i965 driver not supported on Linux."
exit 1
}
if {[have_include power_on/qemu] && $use_i965} {
puts "i965 driver not supported in Qemu."
exit 1
}
set build_components {
core init
drivers/timer
drivers/input
drivers/framebuffer
drivers/gpu/intel
server/liquid_framebuffer
server/nitpicker
lib/mesa/swrast
app/launchpad
app/pointer
}
lappend_if $use_i965 build_components lib/mesa/i965
lappend build_components $demo_component
source ${genode_dir}/repos/base/run/platform_drv.inc
append_platform_drv_build_components
build $build_components
create_boot_directory
set config {
<config prio_levels="2">
<parent-provides>
<service name="CPU"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="LOG"/>
<service name="PD"/>
<service name="RM"/>
<service name="ROM"/>
</parent-provides>
<default caps="100"/>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
}
append_if [have_spec linux] config {
<start name="fb_sdl" caps="200">
<resource name="RAM" quantum="4M"/>
<provides>
<service name="Input"/>
<service name="Framebuffer"/>
</provides>
</start>}
append_platform_drv_config
append_if [expr ![have_spec linux]] config {
<start name="fb_drv">
<resource name="RAM" quantum="10M"/>
<provides>
<service name="Framebuffer"/>
</provides>
<route><any-service> <parent /> <any-child/> </any-service> </route>
</start>}
append_if [have_spec ps2] config {
<start name="ps2_drv">
<resource name="RAM" quantum="2M"/>
<provides> <service name="Input"/> </provides>
</start> }
append config {
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
</start>
<start name="nitpicker" caps="200">
<resource name="RAM" quantum="2M"/>
<provides><service name="Nitpicker"/></provides>
<config>
<domain name="pointer" layer="1" content="client" label="no" origin="pointer" />
<domain name="default" layer="2" content="client" label="no" focus="click" hover="always" />
<policy label_prefix="pointer" domain="pointer"/>
<default-policy domain="default"/>
</config>
<route><any-service><parent/><any-child/></any-service></route>
</start>
<start name="pointer">
<resource name="RAM" quantum="1M"/>
</start>}
#
#
#
set backend_library egl_swrast.lib.so
if {$use_i965} {
set backend_library egl_i965.lib.so
}
set launchpad_config {
<config>
<launcher name="init" ram_quota="1G" caps="2000">
<config verbose="yes">
<parent-provides>
<service name="ROM"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="PD"/>
<service name="RM"/>
<service name="CPU"/>
<service name="LOG"/>
<service name="Nitpicker"/>
<service name="Timer"/>
<service name="Gpu"/>
</parent-provides>
<start name="liquid_fb" caps="200">
<resource name="RAM" quantum="16M"/>
<provides> <service name="Framebuffer"/> <service name="Input"/> </provides>
<config resize_handle="off" animate="off" title="gears" width="600" height="600" xpos="100" ypos="100"/>
<route>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>}
append launchpad_config "
<start name=\"$demo_binary\" caps=\"$demo_caps\">
<resource name=\"RAM\" quantum=\"$demo_ram_quota\"/>"
append launchpad_config $demo_config
append launchpad_config "
<route>
<service name=\"ROM\" label=\"egl_drv.lib.so\">
<parent label=\"$backend_library\"/>
</service>"
append launchpad_config {
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
</config>
</launcher>
</config>}
append config {
<start name="launchpad" caps="512">
<resource name="RAM" quantum="512M"/>}
append config $launchpad_config
append config {
</start>}
append_if $use_i965 config {
<start name="intel_fb_drv" caps="200">
<binary name="intel_gpu_drv"/>
<resource name="RAM" quantum="40M"/>
<provides> <service name="Gpu"/> </provides>
<route>
<any-service> <parent /> <any-child/> </any-service>
</route>
</start>}
append config {
</config>}
install_config $config
set boot_modules {
core init ld.lib.so timer nitpicker pointer liquid_fb
launchpad
libc.lib.so libm.lib.so pthread.lib.so
egl.lib.so mesa.lib.so stdcxx.lib.so
expat.lib.so glapi.lib.so
egl_swrast.lib.so
}
append_if $use_i965 boot_modules {
egl_i965.lib.so drm.lib.so
intel_gpu_drv
}
append boot_modules $demo_modules
lappend_if [have_spec linux] boot_modules fb_sdl
lappend_if [expr ![have_spec linux]] boot_modules fb_drv
lappend_if [have_spec ps2] boot_modules ps2_drv
append_platform_drv_boot_modules
build_boot_image $boot_modules
append qemu_args " -m 768"
run_genode_until forever

View File

@ -28,6 +28,8 @@
#include <base/heap.h>
#include <base/printf.h>
#include <base/debug.h>
#include <framebuffer_session/connection.h>
#include <libc/component.h>
extern "C" {
@ -35,67 +37,84 @@ extern "C" {
#include <sys/select.h>
}
#include <window.h>
static bool initialized = false;
Genode::Env *genode_env;
static Genode::Constructible<Genode::Entrypoint> signal_ep;
struct Eglut_env
Genode::Entrypoint &genode_entrypoint()
{
Libc::Env &env;
Genode::Heap heap { env.ram(), env.rm() };
return *signal_ep;
}
Eglut_env(Libc::Env &env) : env(env) { }
struct Window : Genode_egl_window
{
Genode::Env &env;
Genode::Constructible<Framebuffer::Connection> framebuffer;
Genode::Io_signal_handler<Window> mode_dispatcher;
bool mode_change_pending = false;
Window(Genode::Env &env, int w, int h)
:
env(env),
mode_dispatcher(*signal_ep, *this, &Window::mode_handler)
{
width = w;
height = h;
framebuffer.construct(env, Framebuffer::Mode(width, height, Framebuffer::Mode::RGB565));
addr = env.rm().attach(framebuffer->dataspace());
framebuffer->mode_sigh(mode_dispatcher);
mode_change();
}
void mode_handler()
{
mode_change_pending = true;
}
void update()
{
env.rm().detach(addr);
addr = env.rm().attach(framebuffer->dataspace());
}
void mode_change()
{
Framebuffer::Mode mode = framebuffer->mode();
eglut_window *win = _eglut->current;
if (win) {
win->native.width = mode.width();
win->native.height = mode.height();
width = mode.width();
height = mode.height();
if (win->reshape_cb)
win->reshape_cb(win->native.width, win->native.height);
}
update();
mode_change_pending = false;
}
void refresh()
{
framebuffer->refresh(0, 0, width, height);
}
};
Genode::Constructible<Eglut_env> eglut_env;
Genode::Constructible<Window> eglut_win;
void _eglutNativeInitDisplay()
{
_eglut->surface_type = EGL_WINDOW_BIT;
}
void Window::sync_handler()
{
struct eglut_window *win =_eglut->current;
if (_eglut->idle_cb)
_eglut->idle_cb();
if (win->display_cb)
win->display_cb();
if (initialized) {
eglSwapBuffers(_eglut->dpy, win->surface);
//XXX: required till vsync interrupt
eglWaitClient();
}
}
void Window::mode_handler()
{
if (!framebuffer.is_constructed())
return;
initialized = true;
Framebuffer::Mode mode = framebuffer->mode();
eglut_window *win = _eglut->current;
if (win) {
win->native.width = mode.width();
win->native.height = mode.height();
if (win->reshape_cb)
win->reshape_cb(win->native.width, win->native.height);
}
update();
}
void _eglutNativeFiniDisplay(void)
{
@ -106,7 +125,8 @@ void _eglutNativeFiniDisplay(void)
void _eglutNativeInitWindow(struct eglut_window *win, const char *title,
int x, int y, int w, int h)
{
Genode_egl_window *native = new (eglut_env->heap) Window(eglut_env->env, w, h);
eglut_win.construct(*genode_env, w, h);
Genode_egl_window *native = &*eglut_win;
win->native.u.window = native;
win->native.width = w;
win->native.height = h;
@ -122,7 +142,24 @@ void _eglutNativeFiniWindow(struct eglut_window *win)
void _eglutNativeEventLoop()
{
while (true) {
select(0, nullptr, nullptr, nullptr, nullptr);
struct eglut_window *win =_eglut->current;
if (eglut_win->mode_change_pending) {
eglut_win->mode_change();
}
if (_eglut->idle_cb)
_eglut->idle_cb();
if (win->display_cb)
win->display_cb();
if (eglut_win.is_constructed()) {
eglWaitClient();
eglSwapBuffers(_eglut->dpy, win->surface);
eglut_win->refresh();
}
}
}
@ -135,9 +172,7 @@ extern "C" int eglut_main(int argc, char *argv[]);
void Libc::Component::construct(Libc::Env &env)
{
eglut_env.construct(env);
genode_env = &env;
signal_ep.construct(env, 1024*sizeof(long), "eglut_signal_ep");
Libc::with_libc([] () { eglut_main(1, nullptr); });
}

View File

@ -0,0 +1,53 @@
#define GL_GLEXT_PROTOTYPES
#include <stdlib.h>
#ifdef __APPLE__
# include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glext.h>
#include <EGL/egl.h>
#include "eglut.h"
#endif
#include <math.h>
#include <stdio.h>
/*
* GLUT callbacks:
*/
static void update_timer(void)
{
eglutPostRedisplay();
}
static void render(void)
{
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
glFlush();
}
/*
* Entry point
*/
int eglut_main(int argc, char** argv)
{
eglutInit(argc, argv);
eglutInitWindowSize(600, 600);
eglutInitAPIMask(EGLUT_OPENGL_BIT);
eglutCreateWindow("Triangle");
eglutIdleFunc(&update_timer);
eglutDisplayFunc(&render);
eglutMainLoop();
return 0;
}

View File

@ -0,0 +1,15 @@
TARGET = triangle_gl
LIBS = libm libc egl mesa
SRC_C = eglut.c main.c
SRC_CC = eglut_genode.cc
LD_OPT = --export-dynamic
EGLUT_DIR = $(PRG_DIR)/../eglut
INC_DIR += $(REP_DIR)/src/lib/mesa/include \
$(EGLUT_DIR)
vpath %.c $(EGLUT_DIR)
vpath %.cc $(EGLUT_DIR)