Window manager

The place to share and discuss your Ultibo projects.
pik33
Posts: 889
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Window manager

Postby pik33 » Tue Jul 09, 2019 12:45 pm

There is no Ultibo for RPi4 but then there is a Lazarus on its Raspbian. I am now moving the GUI/Retromachine stuff to this environment and today it made a first run

RPi4 is FAST. The screen refreshing procedure takes less than 3 microsecond (and the Pi4 is working now at 1830 MHz) - it is about 3 microseconds on non-overclocked Pi4.

To do is to move all the applets. Now only sysinfo and calculator works.
Instead of SimpleAudio I will need SDL for the sound. The camera stuff will also need working, as I don't know if there are VC4 and OMX unit for Lazarus/Linux. If this is the case I will have to use Ultibo units for the starting point and try to compile and link them against a Linux libraries.

This is a good learning exercise.

The funny thing is.. I have X (and Lazarus) working on TTY1 and a retromachine on TTY2 so ctrl-alt-f1=x, ctrl-alt-f2=retromachine. Nice :) So I can develop and run it at the same time.

As I wrote earlier it is time to clean all this code up and define a good API for it. Then the Retromachine will be a multiplatform environment.
pik33
Posts: 889
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Window manager

Postby pik33 » Tue Jul 09, 2019 1:35 pm

Update: pjde's icon loader didn't work under Linux. After some tweaking I discovered that this:

Code: Select all

im.LoadFromfile(fn);


works, while this

Code: Select all

im.LoadFromStream(s);


generates an exception ("invalid chunk size" or something similar)

So I simply removed this stream and used im.loadfromfile. It works. I have now to switch to RPi3 and try if it also works with Ultibo this way.
Gavinmc42
Posts: 1662
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: Window manager

Postby Gavinmc42 » Wed Jul 10, 2019 12:17 am

There is no Ultibo for RPi4 but then there is a Lazarus on its Raspbian. I am now moving the GUI/Retromachine stuff to this environment and today it made a first run


I took this battleship game, converted from Delphi and it compiled and ran, except nothing happened.
http://www.pp4s.co.uk/main/prog-battles ... intro.html
Just a matter of working through the code to figure it out.
I think it is the first time I converted any Delphi code?

But it proves that Lazarus and FPC in Raspbian works on a Pi4.
Even got some of the normal Laz image examples working.

Prototyping code in Raspbian with Laz/FPC is looking like a useful step to getting stuff going on Ultibo.
Will it work with OpenGL/ES/VG, maybe but I suspect the Pi4 still needs some drivers for GLES etc

The Pi4 looks to be fast enough for bitmapped gaming, at least the simple 2D ones.
Plus the dual screens is so much nicer to use.

Native QEMU for Ultibo on Pi4? Is that a thing?
pik33
Posts: 889
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Window manager

Postby pik33 » Wed Jul 10, 2019 6:52 am

The Pi4 looks to be fast enough for bitmapped gaming, at least the simple 2D ones.


My screen redrawing procedure which is the heart of the retromachine works in ~2800 microseconds on RPi4 vs ~6000 microseconds on Pi3. The windows compositor gains even more, running in about 3 ms instead of 10..12 ms.

What I had to change was Ultibo related system stuff, so only a few procedures changed inside. The most difficult was to get knowlege how to do this in Linux. For example the "removeramlimits" procedure which allows the code ram to be writable. Or "how to get raw data from a keyboard and a mouse", with the same problem as it was in Ultibo "why there is no mouse wheel data and where can I get it". Then "how to link THE SAME mp3 decoding library as I use with Ultibo".

All solved :)

To do: vc4/camera stuff and audio. I don't even dream of OpenGL in the state of knowledge which I have at this moment.
Gavinmc42
Posts: 1662
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: Window manager

Postby Gavinmc42 » Wed Jul 10, 2019 8:02 am

To do: vc4/camera stuff and audio. I don't even dream of OpenGL in the state of knowledge which I have at this moment.

Camera stuff was talked about recently again in a 64bit post.

First Pi4 driver working is the OpenGL just in last day?
Will test when get home- needs raspi-update.
As it is open source we (er Garry and team) maybe be able to figure it out.

Others like OpenGLES 3.0 will follow I hope.
We now have or soon will have two HDMI, one stereo jack and two PWM audio, plus i2s :D
Not sure how HDMI audio works or how Pi4 jack stereo is done.
pik33
Posts: 889
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Window manager

Postby pik33 » Fri Jul 12, 2019 9:00 am

OpenGL can work without X on RPi4. What works is

Code: Select all

kmscube -D /dev/dri/card1


Rum this without X from a text concole, it displays a rotating cube.
pik33
Posts: 889
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Window manager

Postby pik33 » Sat Jul 13, 2019 3:14 pm

I managed to run a simplest (?) OpenGL ES without X on RPi4.

Code: Select all

// gcc -o drm-gbm drm-gbm-mod.c -ldrm -lgbm -lEGL -lGL -I/usr/include/libdrm

//----------------------------------------------------------------------
//--------  Trying to get OpenGL ES screen on RPi4 without X
//--------  based on drm-gbm https://github.com/eyelash/tutorials/blob/master/drm-gbm.c
//--------  and kmscube https://github.com/robclark/kmscube
//--------  pik33@o2.pl
//----------------------------------------------------------------------

#include <xf86drm.h>
#include <xf86drmMode.h>
#include <gbm.h>
#include <EGL/egl.h>
#include <GL/gl.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#define EXIT(msg) { fputs (msg, stderr); exit (EXIT_FAILURE); }

// global variables declarations

static int device;
static drmModeRes *resources;
static drmModeConnector *connector;
static uint32_t connector_id;
static drmModeEncoder *encoder;
static drmModeModeInfo mode_info;
static drmModeCrtc *crtc;
static struct gbm_device *gbm_device;
static EGLDisplay display;
static EGLContext context;
static struct gbm_surface *gbm_surface;
static EGLSurface egl_surface;
       EGLConfig config;
       EGLint num_config;
       EGLint count=0;
       EGLConfig *configs;
       int config_index;
       int i;
       
static struct gbm_bo *previous_bo = NULL;
static uint32_t previous_fb;       

static EGLint attributes[] = {
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_RED_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_BLUE_SIZE, 8,
      EGL_ALPHA_SIZE, 0,
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
      EGL_NONE
      };

static const EGLint context_attribs[] = {
      EGL_CONTEXT_CLIENT_VERSION, 2,
      EGL_NONE
   };

struct gbm_bo *bo;   
uint32_t handle;
uint32_t pitch;
int32_t fb;
uint64_t modifier;


static drmModeConnector *find_connector (drmModeRes *resources) {

for (i=0; i<resources->count_connectors; i++) {
  drmModeConnector *connector = drmModeGetConnector (device, resources->connectors[i]);
  if (connector->connection == DRM_MODE_CONNECTED) {return connector;}
  drmModeFreeConnector (connector);
  }
return NULL; // if no connector found
}

static drmModeEncoder *find_encoder (drmModeRes *resources, drmModeConnector *connector) {

if (connector->encoder_id) {return drmModeGetEncoder (device, connector->encoder_id);}
return NULL; // if no encoder found
}

static void swap_buffers () {

eglSwapBuffers (display, egl_surface);
bo = gbm_surface_lock_front_buffer (gbm_surface);
handle = gbm_bo_get_handle (bo).u32;
pitch = gbm_bo_get_stride (bo);
drmModeAddFB (device, mode_info.hdisplay, mode_info.vdisplay, 24, 32, pitch, handle, &fb);
drmModeSetCrtc (device, crtc->crtc_id, fb, 0, 0, &connector_id, 1, &mode_info);
if (previous_bo) {
  drmModeRmFB (device, previous_fb);
  gbm_surface_release_buffer (gbm_surface, previous_bo);
  }
previous_bo = bo;
previous_fb = fb;
}

static void draw (float progress) {

glClearColor (1.0f-progress, progress, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
swap_buffers ();
}

static int match_config_to_visual(EGLDisplay egl_display, EGLint visual_id, EGLConfig *configs, int count) {

EGLint id;
for (i = 0; i < count; ++i) {
  if (!eglGetConfigAttrib(egl_display, configs[i], EGL_NATIVE_VISUAL_ID,&id)) continue;
  if (id == visual_id) return i;
  }
return -1;
}

int main () {

device = open ("/dev/dri/card1", O_RDWR);
resources = drmModeGetResources (device);
connector = find_connector (resources);
connector_id = connector->connector_id;
mode_info = connector->modes[0];
encoder = find_encoder (resources, connector);
crtc = drmModeGetCrtc (device, encoder->crtc_id);
drmModeFreeEncoder (encoder);
drmModeFreeConnector (connector);
drmModeFreeResources (resources);
gbm_device = gbm_create_device (device);
gbm_surface = gbm_surface_create (gbm_device, mode_info.hdisplay, mode_info.vdisplay, GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT|GBM_BO_USE_RENDERING);
display = eglGetDisplay (gbm_device);
eglInitialize (display, NULL ,NULL);
eglBindAPI (EGL_OPENGL_API);
eglGetConfigs(display, NULL, 0, &count);
configs = malloc(count * sizeof *configs);
eglChooseConfig (display, attributes, configs, count, &num_config);
config_index = match_config_to_visual(display,GBM_FORMAT_XRGB8888,configs,num_config);
context = eglCreateContext (display, configs[config_index], EGL_NO_CONTEXT, context_attribs);
egl_surface = eglCreateWindowSurface (display, configs[config_index], gbm_surface, NULL);
free(configs);
eglMakeCurrent (display, egl_surface, egl_surface, context);

for (i = 0; i < 600; i++) draw (i / 600.0f);
   
drmModeSetCrtc (device, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, &connector_id, 1, &crtc->mode);
drmModeFreeCrtc (crtc);
if (previous_bo) {
  drmModeRmFB (device, previous_fb);
  gbm_surface_release_buffer (gbm_surface, previous_bo);
  }
eglDestroySurface (display, egl_surface);
gbm_surface_destroy (gbm_surface);
eglDestroyContext (display, context);
eglTerminate (display);
gbm_device_destroy (gbm_device);

close (device);
return 0;
}

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 0 guests