Skip to content

Commit

Permalink
framebuffer: Use pixutils' new pixel group code
Browse files Browse the repository at this point in the history
Update DumbFramebuffer to use pixutils' new pixel group code.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
  • Loading branch information
tomba committed Nov 1, 2024
1 parent 4d610fa commit 79f8b53
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions kms/framebuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mmap
import os
import weakref
from math import ceil

from typing import TYPE_CHECKING

Expand Down Expand Up @@ -64,13 +65,21 @@ class DumbFramebuffer(Framebuffer):
def __init__(self, card: Card, width: int, height: int, format: kms.PixelFormat) -> None:
planes = []

assert width % format.pixelspergroup == 0
assert width % format.pixelspergroup[0] == 0

Check failure on line 68 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.8)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 68 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.9)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 68 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.11)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 68 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.12)

"__getitem__" method not defined on type "int" (reportIndexIssue)

# DRM_IOCTL_MODE_CREATE_DUMB takes a 'bpp' (bits-per-pixel) argument,
# which is then used with the width and height to allocate the buffer.
# This doesn't work for pixel formats where the average bits-per-pixel
# is not an integer (e.g. XV15)
#
# So, we instead use the number of bits per (horizontal) pixel group as
# the 'bpp' argument, and adjust the width accordingly.

for pi in format.planes:
creq = kms.uapi.drm_mode_create_dumb()
creq.width = width
creq.height = height // pi.verticalsubsampling
creq.bpp = pi.bytespergroup * 8 // format.pixelspergroup
creq.width = int(ceil(width / format.pixelspergroup[0]))

Check failure on line 80 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.8)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 80 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.9)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 80 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.11)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 80 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.12)

"__getitem__" method not defined on type "int" (reportIndexIssue)
creq.height = int(ceil(height / format.pixelspergroup[1])) * pi.linespergroup

Check failure on line 81 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.8)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 81 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.8)

Cannot access attribute "linespergroup" for class "PixelFormatPlaneInfo"   Attribute "linespergroup" is unknown (reportAttributeAccessIssue)

Check failure on line 81 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.9)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 81 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Cannot access attribute "linespergroup" for class "PixelFormatPlaneInfo"   Attribute "linespergroup" is unknown (reportAttributeAccessIssue)

Check failure on line 81 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.11)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 81 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Cannot access attribute "linespergroup" for class "PixelFormatPlaneInfo"   Attribute "linespergroup" is unknown (reportAttributeAccessIssue)

Check failure on line 81 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.12)

"__getitem__" method not defined on type "int" (reportIndexIssue)

Check failure on line 81 in kms/framebuffer.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Cannot access attribute "linespergroup" for class "PixelFormatPlaneInfo"   Attribute "linespergroup" is unknown (reportAttributeAccessIssue)
creq.bpp = pi.bytespergroup * 8

fcntl.ioctl(card.fd, kms.uapi.DRM_IOCTL_MODE_CREATE_DUMB, creq, True)

Expand Down

0 comments on commit 79f8b53

Please sign in to comment.