Skip to content

Commit c2c746c

Browse files
committed
framebuffer-spy: Cleanup API, add xovi-message-broker bindings
1 parent 38cfdee commit c2c746c

4 files changed

Lines changed: 36 additions & 20 deletions

File tree

framebuffer-spy/framebuffer-spy-rm2.xovi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
version 0.3.0
1+
version 0.2.0
22

3-
export getFramebufferAddress
43
export getFramebufferConfig
54
export refreshFramebuffer
5+
export getConfigString
6+
with
7+
xovi-message-broker$simpleSignal = "framebuffer-spy$getConfigString"
8+
xovi-message-broker$version = 1
9+
end
10+
611
import? _ZN6QImageC1EPhiiiNS_6FormatEPFvPvES2_
712
override _ZN6QImageC1EPhiiiNS_6FormatEPFvPvES2_
813
with
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
version 0.3.0
1+
version 0.2.0
22

3-
export getFramebufferAddress
43
export getFramebufferConfig
54
export refreshFramebuffer
5+
export getConfigString
6+
with
7+
xovi-message-broker$simpleSignal = "framebuffer-spy$getConfigString"
8+
xovi-message-broker$version = 1
9+
end
610
import? _ZN6QImageC1EPhiixNS_6FormatEPFvPvES2_
711
override _ZN6QImageC1EPhiixNS_6FormatEPFvPvES2_
812

framebuffer-spy/framebuffer-spy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define FBSPY_TYPE_RGBA 2
66

77
struct FramebufferConfig {
8+
void *framebufferAddress;
89
int width, height, type, bpl;
910
bool requiresReload;
1011
};

framebuffer-spy/src/main.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
#include "../xovi.h"
1111
#include "../framebuffer-spy.h"
1212

13-
static void *framebufferData = NULL;
1413
static struct FramebufferConfig config;
14+
static const char *framebufferConfigString = "NULL";
15+
1516
static 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
6065
void 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

8287
void _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

Comments
 (0)