Skip to content

Commit

Permalink
read surface size from shm
Browse files Browse the repository at this point in the history
  • Loading branch information
henkwiedig committed Nov 22, 2024
1 parent 98536af commit 62525f6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
5 changes: 3 additions & 2 deletions osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ static const display_info_t fhd_display_info = {

char font_2_name[256];

uint16_t OVERLAY_WIDTH =1280;
uint16_t OVERLAY_HEIGHT =720;
uint16_t OVERLAY_WIDTH =1800;
uint16_t OVERLAY_HEIGHT =1000;


static displayport_vtable_t *display_driver;
Expand Down Expand Up @@ -1973,6 +1973,7 @@ static void InitMSPHook(){
if (DrawOSD)
Init_x86(&OVERLAY_WIDTH, &OVERLAY_HEIGHT);
height=OVERLAY_HEIGHT;
printf("OSD is %ix%i pixels\n",OVERLAY_WIDTH,OVERLAY_HEIGHT);
#endif

//Get video resolution
Expand Down
73 changes: 59 additions & 14 deletions osd/util/Render_Rockchip.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,77 @@ cairo_surface_t* surface=NULL;
cairo_surface_t* image_surface = NULL;
cairo_t* cr=NULL;
Pixmap backbuffer_pixmap;
cairo_surface_t* backbuffer_surface;

// Define the shared memory region structure
typedef struct {
uint16_t width; // Image width
uint16_t height; // Image height
unsigned char data[]; // Flexible array for image data
} SharedMemoryRegion;

extern int AHI_TiltY;
int Init_x86(uint16_t *width, uint16_t *height) {
// Create shared memory region

const char *shm_name = "msposd"; // Name of the shared memory region

// Open the shared memory segment
int shm_fd = shm_open("msposd", O_RDWR, 0666);
int shm_fd = shm_open(shm_name, O_RDWR, 0666);
if (shm_fd == -1) {
perror("Failed to open shared memory");
perror("Failed to open shared memory");
return -1;
}

// Map just the header to read width and height
size_t header_size = sizeof(SharedMemoryRegion);
SharedMemoryRegion *shm_region = (SharedMemoryRegion *) mmap(0, header_size, PROT_READ, MAP_SHARED, shm_fd, 0);
if (shm_region == MAP_FAILED) {
perror("Failed to map shared memory header");
close(shm_fd);
return -1;
}

// Validate width and height (optional)
if (shm_region->width <= 0 || shm_region->width <= 0) {
fprintf(stderr, "Invalid width or height in shared memory\n");
munmap(shm_region, header_size);
close(shm_fd);
return -1;
}

int shm_width = shm_region->width;
int shm_height = shm_region->height;
*width = shm_region->width;
*height = shm_region->height;

printf("Surface is %ix%i pixels\n",shm_width,shm_height);

// Unmap the header (optional, as we'll remap everything)
munmap(shm_region, header_size);

// Calculate the total size of shared memory
size_t shm_size = header_size + (shm_width * shm_height * 4); // Header + Image data

// Remap the entire shared memory region (header + image data)
shm_region = (SharedMemoryRegion *) mmap(0, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
if (shm_region == MAP_FAILED) {
perror("Failed to remap shared memory");
close(shm_fd);
return -1;
}

// Map the shared memory to the process's address space
size_t shm_size = (*width) * (*height) * 4; // 4 bytes per pixel (RGBA)
unsigned char *shm_data = (unsigned char*) mmap(0, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
if (shm_data == MAP_FAILED) {
perror("Failed to map shared memory");
close(shm_fd);
// Create a Cairo surface for the image data
surface = cairo_image_surface_create_for_data(
shm_region->data, CAIRO_FORMAT_ARGB32, shm_width, shm_height, shm_width * 4);
if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
fprintf(stderr, "Failed to create Cairo surface\n");
munmap(shm_region, shm_size);
close(shm_fd);
return -1;
}

// Create a Cairo image surface on the shared memory buffer
cairo_surface_t *surface = cairo_image_surface_create_for_data(
shm_data, CAIRO_FORMAT_ARGB32, (*width) , (*height), (*width) * 4
);
cr = cairo_create(surface);
// Create a Cairo context
cr = cairo_create(surface);

}

Expand Down

0 comments on commit 62525f6

Please sign in to comment.