79
79
80
80
typedef struct {
81
81
struct gbm_bo * bo ;
82
- uint32_t fb_id ; // DRM framebuffer ID
82
+ uint32_t fbId ; // DRM framebuffer ID
83
83
} FramebufferCache ;
84
84
85
- static FramebufferCache fbCache [MAX_CACHED_BOS ];
85
+ static FramebufferCache fbCache [MAX_CACHED_BOS ] = { 0 } ;
86
86
static volatile int fbCacheCount = 0 ;
87
87
static volatile bool pendingFlip = false;
88
88
static bool crtcSet = false;
@@ -570,13 +570,14 @@ void DisableCursor(void)
570
570
}
571
571
572
572
#if defined(SUPPORT_DRM_CACHE )
573
- static void drm_fb_destroy_callback (struct gbm_bo * bo , void * data ) {
574
- uint32_t fb_id = (uintptr_t )data ;
573
+ //callback to destroy cached framebuffer, set by gbm_bo_set_user_data()
574
+ static void DestroyFrameBufferCallback (struct gbm_bo * bo , void * data ) {
575
+ uint32_t fbId = (uintptr_t )data ;
575
576
// Remove from cache
576
577
for (int i = 0 ; i < fbCacheCount ; i ++ ) {
577
578
if (fbCache [i ].bo == bo ) {
578
- TRACELOG (LOG_INFO , "DRM: fb removed %u" , (uintptr_t )fb_id );
579
- drmModeRmFB (platform .fd , fbCache [i ].fb_id ); // Release DRM FB
579
+ TRACELOG (LOG_INFO , "DRM: fb removed %u" , (uintptr_t )fbId );
580
+ drmModeRmFB (platform .fd , fbCache [i ].fbId ); // Release DRM FB
580
581
// Shift remaining entries
581
582
for (int j = i ; j < fbCacheCount - 1 ; j ++ ) {
582
583
fbCache [j ] = fbCache [j + 1 ];
@@ -588,11 +589,11 @@ static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) {
588
589
}
589
590
590
591
// Create or retrieve cached DRM FB for BO
591
- static uint32_t get_or_create_fb_for_bo (struct gbm_bo * bo ) {
592
+ static uint32_t GetOrCreateFbForBo (struct gbm_bo * bo ) {
592
593
// Try to find existing cache entry
593
594
for (int i = 0 ; i < fbCacheCount ; i ++ ) {
594
595
if (fbCache [i ].bo == bo ) {
595
- return fbCache [i ].fb_id ;
596
+ return fbCache [i ].fbId ;
596
597
}
597
598
}
598
599
@@ -607,21 +608,21 @@ static uint32_t get_or_create_fb_for_bo(struct gbm_bo *bo) {
607
608
uint32_t width = gbm_bo_get_width (bo );
608
609
uint32_t height = gbm_bo_get_height (bo );
609
610
610
- uint32_t fb_id ;
611
- if (drmModeAddFB (platform .fd , width , height , 24 , 32 , stride , handle , & fb_id )) {
611
+ uint32_t fbId ;
612
+ if (drmModeAddFB (platform .fd , width , height , 24 , 32 , stride , handle , & fbId )) {
612
613
//rmModeAddFB failed
613
614
return 0 ;
614
615
}
615
616
616
617
// Store in cache
617
- fbCache [fbCacheCount ] = (FramebufferCache ){ .bo = bo , .fb_id = fb_id };
618
+ fbCache [fbCacheCount ] = (FramebufferCache ){ .bo = bo , .fbId = fbId };
618
619
fbCacheCount ++ ;
619
620
620
621
// Set destroy callback to auto-cleanup
621
- gbm_bo_set_user_data (bo , (void * )(uintptr_t )fb_id , drm_fb_destroy_callback );
622
+ gbm_bo_set_user_data (bo , (void * )(uintptr_t )fbId , DestroyFrameBufferCallback );
622
623
623
- TRACELOG (LOG_INFO , "DRM: added new bo %u" , (uintptr_t )fb_id );
624
- return fb_id ;
624
+ TRACELOG (LOG_INFO , "DRM: added new bo %u" , (uintptr_t )fbId );
625
+ return fbId ;
625
626
}
626
627
627
628
// Renders a blank frame to allocate initial buffers
@@ -652,14 +653,14 @@ int InitSwapScreenBuffer() {
652
653
}
653
654
654
655
// Create FB for first buffer
655
- uint32_t fb_id = get_or_create_fb_for_bo (bo );
656
- if (!fb_id ) {
656
+ uint32_t fbId = GetOrCreateFbForBo (bo );
657
+ if (!fbId ) {
657
658
gbm_surface_release_buffer (platform .gbmSurface , bo );
658
659
return -1 ;
659
660
}
660
661
661
662
// Initial CRTC setup
662
- if (drmModeSetCrtc (platform .fd , platform .crtc -> crtc_id , fb_id ,
663
+ if (drmModeSetCrtc (platform .fd , platform .crtc -> crtc_id , fbId ,
663
664
0 , 0 , & platform .connector -> connector_id , 1 ,
664
665
& platform .connector -> modes [platform .modeIndex ])) {
665
666
TRACELOG (LOG_ERROR , "Initial CRTC setup failed: %s" , strerror (errno ));
@@ -675,7 +676,7 @@ int InitSwapScreenBuffer() {
675
676
676
677
// Static page flip handler
677
678
// this will be called once the drmModePageFlip() finished from the drmHandleEvent(platform.fd, &evctx); context
678
- static void page_flip_handler (int fd , unsigned int frame ,
679
+ static void PageFlipHandler (int fd , unsigned int frame ,
679
680
unsigned int sec , unsigned int usec ,
680
681
void * data ) {
681
682
(void )fd ; (void )frame ; (void )sec ; (void )usec ; // Unused
@@ -701,7 +702,7 @@ void SwapScreenBuffer() {
701
702
// Process pending events non-blocking
702
703
drmEventContext evctx = {
703
704
.version = DRM_EVENT_CONTEXT_VERSION ,
704
- .page_flip_handler = page_flip_handler
705
+ .page_flip_handler = PageFlipHandler
705
706
};
706
707
707
708
struct pollfd pfd = { .fd = platform .fd , .events = POLLIN };
@@ -726,8 +727,8 @@ void SwapScreenBuffer() {
726
727
}
727
728
728
729
// Get FB ID (creates new one if needed)
729
- uint32_t fb_id = get_or_create_fb_for_bo (next_bo );
730
- if (!fb_id ) {
730
+ uint32_t fbId = GetOrCreateFbForBo (next_bo );
731
+ if (!fbId ) {
731
732
gbm_surface_release_buffer (platform .gbmSurface , next_bo );
732
733
errCnt [2 ]++ ;
733
734
return ;
@@ -744,7 +745,7 @@ void SwapScreenBuffer() {
744
745
* is rendered..
745
746
* returns immediately.
746
747
*/
747
- if (drmModePageFlip (platform .fd , platform .crtc -> crtc_id , fb_id ,
748
+ if (drmModePageFlip (platform .fd , platform .crtc -> crtc_id , fbId ,
748
749
DRM_MODE_PAGE_FLIP_EVENT , platform .prevBO )) {
749
750
if (errno == EBUSY ) {
750
751
//Display busy - skip flip
0 commit comments