Skip to content

Commit 5b18213

Browse files
committed
- implementing Raylib coding convention
1 parent de62be0 commit 5b18213

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/platforms/rcore_drm.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979

8080
typedef struct {
8181
struct gbm_bo *bo;
82-
uint32_t fb_id; // DRM framebuffer ID
82+
uint32_t fbId; // DRM framebuffer ID
8383
} FramebufferCache;
8484

85-
static FramebufferCache fbCache[MAX_CACHED_BOS];
85+
static FramebufferCache fbCache[MAX_CACHED_BOS] = {0};
8686
static volatile int fbCacheCount = 0;
8787
static volatile bool pendingFlip = false;
8888
static bool crtcSet = false;
@@ -570,13 +570,14 @@ void DisableCursor(void)
570570
}
571571

572572
#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;
575576
// Remove from cache
576577
for (int i = 0; i < fbCacheCount; i++) {
577578
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
580581
// Shift remaining entries
581582
for (int j = i; j < fbCacheCount - 1; j++) {
582583
fbCache[j] = fbCache[j + 1];
@@ -588,11 +589,11 @@ static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) {
588589
}
589590

590591
// 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) {
592593
// Try to find existing cache entry
593594
for (int i = 0; i < fbCacheCount; i++) {
594595
if (fbCache[i].bo == bo) {
595-
return fbCache[i].fb_id;
596+
return fbCache[i].fbId;
596597
}
597598
}
598599

@@ -607,21 +608,21 @@ static uint32_t get_or_create_fb_for_bo(struct gbm_bo *bo) {
607608
uint32_t width = gbm_bo_get_width(bo);
608609
uint32_t height = gbm_bo_get_height(bo);
609610

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)) {
612613
//rmModeAddFB failed
613614
return 0;
614615
}
615616

616617
// Store in cache
617-
fbCache[fbCacheCount] = (FramebufferCache){ .bo = bo, .fb_id = fb_id };
618+
fbCache[fbCacheCount] = (FramebufferCache){ .bo = bo, .fbId = fbId };
618619
fbCacheCount++;
619620

620621
// 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);
622623

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;
625626
}
626627

627628
// Renders a blank frame to allocate initial buffers
@@ -652,14 +653,14 @@ int InitSwapScreenBuffer() {
652653
}
653654

654655
// 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) {
657658
gbm_surface_release_buffer(platform.gbmSurface, bo);
658659
return -1;
659660
}
660661

661662
// Initial CRTC setup
662-
if (drmModeSetCrtc(platform.fd, platform.crtc->crtc_id, fb_id,
663+
if (drmModeSetCrtc(platform.fd, platform.crtc->crtc_id, fbId,
663664
0, 0, &platform.connector->connector_id, 1,
664665
&platform.connector->modes[platform.modeIndex])) {
665666
TRACELOG(LOG_ERROR, "Initial CRTC setup failed: %s", strerror(errno));
@@ -675,7 +676,7 @@ int InitSwapScreenBuffer() {
675676

676677
// Static page flip handler
677678
// 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,
679680
unsigned int sec, unsigned int usec,
680681
void *data) {
681682
(void)fd; (void)frame; (void)sec; (void)usec; // Unused
@@ -701,7 +702,7 @@ void SwapScreenBuffer() {
701702
// Process pending events non-blocking
702703
drmEventContext evctx = {
703704
.version = DRM_EVENT_CONTEXT_VERSION,
704-
.page_flip_handler = page_flip_handler
705+
.page_flip_handler = PageFlipHandler
705706
};
706707

707708
struct pollfd pfd = { .fd = platform.fd, .events = POLLIN };
@@ -726,8 +727,8 @@ void SwapScreenBuffer() {
726727
}
727728

728729
// 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) {
731732
gbm_surface_release_buffer(platform.gbmSurface, next_bo);
732733
errCnt[2]++;
733734
return;
@@ -744,7 +745,7 @@ void SwapScreenBuffer() {
744745
* is rendered..
745746
* returns immediately.
746747
*/
747-
if (drmModePageFlip(platform.fd, platform.crtc->crtc_id, fb_id,
748+
if (drmModePageFlip(platform.fd, platform.crtc->crtc_id, fbId,
748749
DRM_MODE_PAGE_FLIP_EVENT, platform.prevBO)) {
749750
if (errno == EBUSY) {
750751
//Display busy - skip flip

0 commit comments

Comments
 (0)