1010#include "../xovi.h"
1111#include "../framebuffer-spy.h"
1212
13- static void * framebufferData = NULL ;
1413static struct FramebufferConfig config ;
14+ static const char * framebufferConfigString = "NULL" ;
15+
1516static int sizeMap ;
1617
17- void setFramebufferAddress (void * data ) {
18- fprintf (stderr , "Found framebuffer! Address is %p\n" , data );
19- framebufferData = data ;
20- char temp [50 ];
21- snprintf (temp , sizeof (temp ), "%p" , framebufferData );
22- setenv ("FRAMEBUFFER_SPY_EXTENSION_FBADDR" , temp , 1 );
18+ static void prepareConfigString () {
19+ framebufferConfigString = malloc (1024 );
20+ snprintf ((char * ) framebufferConfigString , 1024 ,
21+ "%p,%d,%d,%d,%d,%d" ,
22+ config .framebufferAddress ,
23+ config .width , config .height ,
24+ config .type , config .bpl ,
25+ config .requiresReload );
26+ fprintf (stderr , "Found framebuffer! Config string is %s\n" , framebufferConfigString );
2327}
2428
2529#ifdef __aarch64__
@@ -31,13 +35,14 @@ void override$_ZN6QImageC1EPhiiiNS_6FormatEPFvPvES2_(void *that, void *data, int
3135 bool rmppmCondition = x == 960 && y == 1696 && bpl == 3840 && f == 4 ;
3236 bool rmppCondition = x == 1620 && y == 2160 && bpl == 6528 && f == 4 ;
3337 bool rm2Condition = x == 1404 && y == 1872 && ((bpl == 2808 && f == 7 ) || (bpl == 5616 && f == 4 ));
34- if ((rmppmCondition || rmppCondition || rm2Condition ) && framebufferData == NULL ) {
35- setFramebufferAddress (data );
38+ if ((rmppmCondition || rmppCondition || rm2Condition ) && config .framebufferAddress == NULL ) {
3639 config .width = x ;
3740 config .height = y ;
3841 config .type = f == 4 ? FBSPY_TYPE_RGBA : FBSPY_TYPE_RGB565 ;
3942 config .bpl = bpl ;
4043 config .requiresReload = false;
44+ config .framebufferAddress = data ;
45+ prepareConfigString ();
4146 }
4247#ifdef __aarch64__
4348 $_ZN6QImageC1EPhiixNS_6FormatEPFvPvES2_ (that , data , x , y , bpl , f , a , b );
@@ -47,19 +52,19 @@ void override$_ZN6QImageC1EPhiiiNS_6FormatEPFvPvES2_(void *that, void *data, int
4752}
4853
4954// export
50- void * getFramebufferAddress () {
51- return framebufferData ;
55+ struct FramebufferConfig getFramebufferConfig () {
56+ return config ;
5257}
5358
5459// export
55- struct FramebufferConfig getFramebufferConfig () {
56- return config ;
60+ char * getConfigString () {
61+ return strdup ( framebufferConfigString ) ;
5762}
5863
5964// export
6065void refreshFramebuffer () {
6166 if (config .requiresReload ) {
62- msync (framebufferData , sizeMap , MS_SYNC );
67+ msync (config . framebufferAddress , sizeMap , MS_SYNC );
6368 }
6469}
6570
@@ -69,19 +74,20 @@ static void prepareRM1() {
6974 sizeMap = 1872 * 1408 * 2 ;
7075 fprintf (stderr , "Framebuffer detected as a device file (fd=%d, size=%u) - mmaping...\n" , fd , sizeMap );
7176 void * data = mmap (NULL , sizeMap , PROT_READ , MAP_SHARED , fd , 0 );
72- setFramebufferAddress (data );
73- setenv ("FRAMEBUFFER_SPY_REQUIRE_MSYNC" , "1" , 1 );
7477 config .width = 1408 ;
7578 config .height = 1872 ;
7679 config .type = FBSPY_TYPE_RGB565 ;
7780 config .bpl = config .width * 2 ;
7881 config .requiresReload = true;
82+ config .framebufferAddress = data ;
83+ prepareConfigString ();
7984 }
8085}
8186
8287void _xovi_construct () {
8388 // Check if this is an rM1:
8489 char * data = malloc (1024 );
90+ config .framebufferAddress = NULL ;
8591 int devFD = open ("/sys/devices/soc0/machine" , O_RDONLY );
8692 if (devFD > -1 ) {
8793 int r = read (devFD , data , 1023 );
0 commit comments