From 90f783f3ca34134298c6220b9223da08319804b3 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Tue, 30 Mar 2021 08:59:19 -0400 Subject: use create_dumb.size as size of buffer According to `man drm-memory` , "The size field contains the absolute size in bytes of the buffer. This can normally also be computed with (height * pitch + width) * bpp / 4". Which suggests that we should use the .size field to allocate buffer. Test: th Test: go to recovery, make sure contents are properly displayed. BYPASS_INCLUSIVE_LANGUAGE_REASON=commit message referenced "man", which is a linux command for lookup manual pages. Change-Id: I512be6b7d493ef1783f2b7f746e279bc1dfe65f2 --- minui/graphics_drm.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/minui/graphics_drm.cpp b/minui/graphics_drm.cpp index 95759e382..9d31ff7a9 100644 --- a/minui/graphics_drm.cpp +++ b/minui/graphics_drm.cpp @@ -105,6 +105,8 @@ std::unique_ptr GRSurfaceDrm::Create(int drm_fd, int width, int he perror("Failed to DRM_IOCTL_MODE_CREATE_DUMB"); return nullptr; } + printf("Allocating buffer with resolution %d x %d pitch: %d bpp: %d, size: %llu\n", width, height, + create_dumb.pitch, create_dumb.bpp, create_dumb.size); // Cannot use std::make_unique to access non-public ctor. auto surface = std::unique_ptr(new GRSurfaceDrm( @@ -128,13 +130,14 @@ std::unique_ptr GRSurfaceDrm::Create(int drm_fd, int width, int he return nullptr; } - auto mmapped = mmap(nullptr, surface->height * surface->row_bytes, PROT_READ | PROT_WRITE, - MAP_SHARED, drm_fd, map_dumb.offset); + auto mmapped = + mmap(nullptr, create_dumb.size, PROT_READ | PROT_WRITE, MAP_SHARED, drm_fd, map_dumb.offset); if (mmapped == MAP_FAILED) { perror("Failed to mmap()"); return nullptr; } surface->mmapped_buffer_ = static_cast(mmapped); + printf("Framebuffer of size %llu allocated @ %p\n", create_dumb.size, surface->mmapped_buffer_); return surface; } @@ -260,9 +263,16 @@ drmModeConnector* MinuiBackendDrm::FindMainMonitor(int fd, drmModeRes* resources /* If we still didn't find a connector, give up and return. */ if (!main_monitor_connector) return nullptr; + for (int modes = 0; modes < main_monitor_connector->count_modes; modes++) { + printf("Display Mode %d resolution: %d x %d @ %d FPS\n", modes, + main_monitor_connector->modes[modes].hdisplay, + main_monitor_connector->modes[modes].vdisplay, + main_monitor_connector->modes[modes].vrefresh); + } *mode_index = 0; for (int modes = 0; modes < main_monitor_connector->count_modes; modes++) { if (main_monitor_connector->modes[modes].type & DRM_MODE_TYPE_PREFERRED) { + printf("Choosing display mode #%d\n", modes); *mode_index = modes; break; } -- cgit v1.2.3