summaryrefslogtreecommitdiff
path: root/src/screen
diff options
context:
space:
mode:
Diffstat (limited to 'src/screen')
-rw-r--r--src/screen/cerror.zig533
-rw-r--r--src/screen/drm/card.zig100
-rw-r--r--src/screen/drm/connector/connection.zig8
-rw-r--r--src/screen/drm/connector/mode.zig112
-rw-r--r--src/screen/drm/connector/root.zig161
-rw-r--r--src/screen/drm/connector/type.zig42
-rw-r--r--src/screen/drm/crtc/root.zig178
-rw-r--r--src/screen/drm/encoder/root.zig50
-rw-r--r--src/screen/drm/encoder/type.zig18
-rw-r--r--src/screen/drm/event.zig32
-rw-r--r--src/screen/drm/frame-buffer/page-flip.zig11
-rw-r--r--src/screen/drm/frame-buffer/pixelformat.zig10
-rw-r--r--src/screen/drm/frame-buffer/root.zig280
-rw-r--r--src/screen/drm/request.zig36
-rw-r--r--src/screen/drm/resources.zig114
-rw-r--r--src/screen/main.zig169
16 files changed, 928 insertions, 926 deletions
diff --git a/src/screen/cerror.zig b/src/screen/cerror.zig
index cd7f6e6..15f3f24 100644
--- a/src/screen/cerror.zig
+++ b/src/screen/cerror.zig
@@ -1,272 +1,271 @@
-
pub const CError = error {
- OperationNotPermitted,
- NoSuchFileOrDirectory,
- NoSuchProcess,
- InterruptedSystemCall,
- InputOutputError,
- NoSuchDeviceOrAddress,
- ArgumentListTooLong,
- ExecFormatError,
- BadFileDescriptor,
- NoChildProcesses,
- ResourceTemporarilyUnavailable,
- CannotAllocateMemory,
- PermissionDenied,
- BadAddress,
- BlockDeviceRequired,
- DeviceOrResourceBusy,
- FileExists,
- InvalidCrossDeviceLink,
- NoSuchDevice,
- NotADirectory,
- IsADirectory,
- InvalidArgument,
- TooManyOpenFilesInSystem,
- TooManyOpenFiles,
- InappropriateIoctlForDevice,
- TextFileBusy,
- FileTooLarge,
- NoSpaceLeftOnDevice,
- IllegalSeek,
- ReadOnlyFileSystem,
- TooManyLinks,
- BrokenPipe,
- NumericalArgumentOutOfDomain,
- NumericalResultOutOfRange,
- ResourceDeadlockAvoided,
- FileNameTooLong,
- NoLocksAvailable,
- FunctionNotImplemented,
- DirectoryNotEmpty,
- TooManyLevelsOfSymbolicLinks,
- NoMessageOfDesiredType,
- IdentifierRemoved,
- ChannelNumberOutOfRange,
- Level2NotSynchronized,
- Level3Halted,
- Level3Reset,
- LinkNumberOutOfRange,
- ProtocolDriverNotAttached,
- NoCSIStructureAvailable,
- Level2Halted,
- InvalidExchange,
- InvalidRequestDescriptor,
- ExchangeFull,
- NoAnode,
- InvalidRequestCode,
- InvalidSlot,
- BadFontFileFormat,
- DeviceNotAStream,
- NoDataAvailable,
- TimerExpired,
- OutOfStreamsResources,
- MachineIsNotOnTheNetwork,
- PackageNotInstalled,
- ObjectIsRemote,
- LinkHasBeenSevered,
- AdvertiseError,
- SrmountError,
- CommunicationErrorOnSend,
- ProtocolError,
- MultihopAttempted,
- RFSSpecificError,
- BadMessage,
- ValueTooLargeForDefinedDataType,
- NameNotUniqueOnNetwork,
- FileDescriptorInBadState,
- RemoteAddressChanged,
- CanNotAccessANeededSharedLibrary,
- AccessingACorruptedSharedLibrary,
- LibSectionInAOutCorrupted,
- AttemptingToLinkInTooManySharedLibraries,
- CannotExecASharedLibraryDirectly,
- InvalidOrIncompleteMultibyteOrWideCharacter,
- InterruptedSystemCallShouldBeRestarted,
- StreamsPipeError,
- TooManyUsers,
- SocketOperationOnNonSocket,
- DestinationAddressRequired,
- MessageTooLong,
- ProtocolWrongTypeForSocket,
- ProtocolNotAvailable,
- ProtocolNotSupported,
- SocketTypeNotSupported,
- OperationNotSupported,
- ProtocolFamilyNotSupported,
- AddressFamilyNotSupportedByProtocol,
- AddressAlreadyInUse,
- CannotAssignRequestedAddress,
- NetworkIsDown,
- NetworkIsUnreachable,
- NetworkDroppedConnectionOnReset,
- SoftwareCausedConnectionAbort,
- ConnectionResetByPeer,
- NoBufferSpaceAvailable,
- TransportEndpointIsAlreadyConnected,
- TransportEndpointIsNotConnected,
- CannotSendAfterTransportEndpointShutdown,
- TooManyReferences,
- ConnectionTimedOut,
- ConnectionRefused,
- HostIsDown,
- NoRouteToHost,
- OperationAlreadyInProgress,
- OperationNowInProgress,
- StaleFileHandle,
- StructureNeedsCleaning,
- NotAXENIXNamedTypeFile,
- NoXENIXSemaphoresAvailable,
- IsANamedTypeFile,
- RemoteIOError,
- DiskQuotaExceeded,
- NoMediumFound,
- WrongMediumType,
- OperationCanceled,
- RequiredKeyNotAvailable,
- KeyHasExpired,
- KeyHasBeenRevoked,
- KeyWasRejectedByService,
- OwnerDied,
- StateNotRecoverable,
- OperationNotPossibleDueToRFKill,
- MemoryPageHasHardwareError,
+ OperationNotPermitted,
+ NoSuchFileOrDirectory,
+ NoSuchProcess,
+ InterruptedSystemCall,
+ InputOutputError,
+ NoSuchDeviceOrAddress,
+ ArgumentListTooLong,
+ ExecFormatError,
+ BadFileDescriptor,
+ NoChildProcesses,
+ ResourceTemporarilyUnavailable,
+ CannotAllocateMemory,
+ PermissionDenied,
+ BadAddress,
+ BlockDeviceRequired,
+ DeviceOrResourceBusy,
+ FileExists,
+ InvalidCrossDeviceLink,
+ NoSuchDevice,
+ NotADirectory,
+ IsADirectory,
+ InvalidArgument,
+ TooManyOpenFilesInSystem,
+ TooManyOpenFiles,
+ InappropriateIoctlForDevice,
+ TextFileBusy,
+ FileTooLarge,
+ NoSpaceLeftOnDevice,
+ IllegalSeek,
+ ReadOnlyFileSystem,
+ TooManyLinks,
+ BrokenPipe,
+ NumericalArgumentOutOfDomain,
+ NumericalResultOutOfRange,
+ ResourceDeadlockAvoided,
+ FileNameTooLong,
+ NoLocksAvailable,
+ FunctionNotImplemented,
+ DirectoryNotEmpty,
+ TooManyLevelsOfSymbolicLinks,
+ NoMessageOfDesiredType,
+ IdentifierRemoved,
+ ChannelNumberOutOfRange,
+ Level2NotSynchronized,
+ Level3Halted,
+ Level3Reset,
+ LinkNumberOutOfRange,
+ ProtocolDriverNotAttached,
+ NoCSIStructureAvailable,
+ Level2Halted,
+ InvalidExchange,
+ InvalidRequestDescriptor,
+ ExchangeFull,
+ NoAnode,
+ InvalidRequestCode,
+ InvalidSlot,
+ BadFontFileFormat,
+ DeviceNotAStream,
+ NoDataAvailable,
+ TimerExpired,
+ OutOfStreamsResources,
+ MachineIsNotOnTheNetwork,
+ PackageNotInstalled,
+ ObjectIsRemote,
+ LinkHasBeenSevered,
+ AdvertiseError,
+ SrmountError,
+ CommunicationErrorOnSend,
+ ProtocolError,
+ MultihopAttempted,
+ RFSSpecificError,
+ BadMessage,
+ ValueTooLargeForDefinedDataType,
+ NameNotUniqueOnNetwork,
+ FileDescriptorInBadState,
+ RemoteAddressChanged,
+ CanNotAccessANeededSharedLibrary,
+ AccessingACorruptedSharedLibrary,
+ LibSectionInAOutCorrupted,
+ AttemptingToLinkInTooManySharedLibraries,
+ CannotExecASharedLibraryDirectly,
+ InvalidOrIncompleteMultibyteOrWideCharacter,
+ InterruptedSystemCallShouldBeRestarted,
+ StreamsPipeError,
+ TooManyUsers,
+ SocketOperationOnNonSocket,
+ DestinationAddressRequired,
+ MessageTooLong,
+ ProtocolWrongTypeForSocket,
+ ProtocolNotAvailable,
+ ProtocolNotSupported,
+ SocketTypeNotSupported,
+ OperationNotSupported,
+ ProtocolFamilyNotSupported,
+ AddressFamilyNotSupportedByProtocol,
+ AddressAlreadyInUse,
+ CannotAssignRequestedAddress,
+ NetworkIsDown,
+ NetworkIsUnreachable,
+ NetworkDroppedConnectionOnReset,
+ SoftwareCausedConnectionAbort,
+ ConnectionResetByPeer,
+ NoBufferSpaceAvailable,
+ TransportEndpointIsAlreadyConnected,
+ TransportEndpointIsNotConnected,
+ CannotSendAfterTransportEndpointShutdown,
+ TooManyReferences,
+ ConnectionTimedOut,
+ ConnectionRefused,
+ HostIsDown,
+ NoRouteToHost,
+ OperationAlreadyInProgress,
+ OperationNowInProgress,
+ StaleFileHandle,
+ StructureNeedsCleaning,
+ NotAXENIXNamedTypeFile,
+ NoXENIXSemaphoresAvailable,
+ IsANamedTypeFile,
+ RemoteIOError,
+ DiskQuotaExceeded,
+ NoMediumFound,
+ WrongMediumType,
+ OperationCanceled,
+ RequiredKeyNotAvailable,
+ KeyHasExpired,
+ KeyHasBeenRevoked,
+ KeyWasRejectedByService,
+ OwnerDied,
+ StateNotRecoverable,
+ OperationNotPossibleDueToRFKill,
+ MemoryPageHasHardwareError,
};
pub fn from_usize(errno: usize) CError!void {
- const n = -@as(isize, @bitCast(errno));
- return switch (n) {
- 1 => CError.OperationNotPermitted,
- 2 => CError.NoSuchFileOrDirectory,
- 3 => CError.NoSuchProcess,
- 4 => CError.InterruptedSystemCall,
- 5 => CError.InputOutputError,
- 6 => CError.NoSuchDeviceOrAddress,
- 7 => CError.ArgumentListTooLong,
- 8 => CError.ExecFormatError,
- 9 => CError.BadFileDescriptor,
- 10 => CError.NoChildProcesses,
- 11 => CError.ResourceTemporarilyUnavailable,
- 12 => CError.CannotAllocateMemory,
- 13 => CError.PermissionDenied,
- 14 => CError.BadAddress,
- 15 => CError.BlockDeviceRequired,
- 16 => CError.DeviceOrResourceBusy,
- 17 => CError.FileExists,
- 18 => CError.InvalidCrossDeviceLink,
- 19 => CError.NoSuchDevice,
- 20 => CError.NotADirectory,
- 21 => CError.IsADirectory,
- 22 => CError.InvalidArgument,
- 23 => CError.TooManyOpenFilesInSystem,
- 24 => CError.TooManyOpenFiles,
- 25 => CError.InappropriateIoctlForDevice,
- 26 => CError.TextFileBusy,
- 27 => CError.FileTooLarge,
- 28 => CError.NoSpaceLeftOnDevice,
- 29 => CError.IllegalSeek,
- 30 => CError.ReadOnlyFileSystem,
- 31 => CError.TooManyLinks,
- 32 => CError.BrokenPipe,
- 33 => CError.NumericalArgumentOutOfDomain,
- 34 => CError.NumericalResultOutOfRange,
- 35 => CError.ResourceDeadlockAvoided,
- 36 => CError.FileNameTooLong,
- 37 => CError.NoLocksAvailable,
- 38 => CError.FunctionNotImplemented,
- 39 => CError.DirectoryNotEmpty,
- 40 => CError.TooManyLevelsOfSymbolicLinks,
- 42 => CError.NoMessageOfDesiredType,
- 43 => CError.IdentifierRemoved,
- 44 => CError.ChannelNumberOutOfRange,
- 45 => CError.Level2NotSynchronized,
- 46 => CError.Level3Halted,
- 47 => CError.Level3Reset,
- 48 => CError.LinkNumberOutOfRange,
- 49 => CError.ProtocolDriverNotAttached,
- 50 => CError.NoCSIStructureAvailable,
- 51 => CError.Level2Halted,
- 52 => CError.InvalidExchange,
- 53 => CError.InvalidRequestDescriptor,
- 54 => CError.ExchangeFull,
- 55 => CError.NoAnode,
- 56 => CError.InvalidRequestCode,
- 57 => CError.InvalidSlot,
- 59 => CError.BadFontFileFormat,
- 60 => CError.DeviceNotAStream,
- 61 => CError.NoDataAvailable,
- 62 => CError.TimerExpired,
- 63 => CError.OutOfStreamsResources,
- 64 => CError.MachineIsNotOnTheNetwork,
- 65 => CError.PackageNotInstalled,
- 66 => CError.ObjectIsRemote,
- 67 => CError.LinkHasBeenSevered,
- 68 => CError.AdvertiseError,
- 69 => CError.SrmountError,
- 70 => CError.CommunicationErrorOnSend,
- 71 => CError.ProtocolError,
- 72 => CError.MultihopAttempted,
- 73 => CError.RFSSpecificError,
- 74 => CError.BadMessage,
- 75 => CError.ValueTooLargeForDefinedDataType,
- 76 => CError.NameNotUniqueOnNetwork,
- 77 => CError.FileDescriptorInBadState,
- 78 => CError.RemoteAddressChanged,
- 79 => CError.CanNotAccessANeededSharedLibrary,
- 80 => CError.AccessingACorruptedSharedLibrary,
- 81 => CError.LibSectionInAOutCorrupted,
- 82 => CError.AttemptingToLinkInTooManySharedLibraries,
- 83 => CError.CannotExecASharedLibraryDirectly,
- 84 => CError.InvalidOrIncompleteMultibyteOrWideCharacter,
- 85 => CError.InterruptedSystemCallShouldBeRestarted,
- 86 => CError.StreamsPipeError,
- 87 => CError.TooManyUsers,
- 88 => CError.SocketOperationOnNonSocket,
- 89 => CError.DestinationAddressRequired,
- 90 => CError.MessageTooLong,
- 91 => CError.ProtocolWrongTypeForSocket,
- 92 => CError.ProtocolNotAvailable,
- 93 => CError.ProtocolNotSupported,
- 94 => CError.SocketTypeNotSupported,
- 95 => CError.OperationNotSupported,
- 96 => CError.ProtocolFamilyNotSupported,
- 97 => CError.AddressFamilyNotSupportedByProtocol,
- 98 => CError.AddressAlreadyInUse,
- 99 => CError.CannotAssignRequestedAddress,
- 100 => CError.NetworkIsDown,
- 101 => CError.NetworkIsUnreachable,
- 102 => CError.NetworkDroppedConnectionOnReset,
- 103 => CError.SoftwareCausedConnectionAbort,
- 104 => CError.ConnectionResetByPeer,
- 105 => CError.NoBufferSpaceAvailable,
- 106 => CError.TransportEndpointIsAlreadyConnected,
- 107 => CError.TransportEndpointIsNotConnected,
- 108 => CError.CannotSendAfterTransportEndpointShutdown,
- 109 => CError.TooManyReferences,
- 110 => CError.ConnectionTimedOut,
- 111 => CError.ConnectionRefused,
- 112 => CError.HostIsDown,
- 113 => CError.NoRouteToHost,
- 114 => CError.OperationAlreadyInProgress,
- 115 => CError.OperationNowInProgress,
- 116 => CError.StaleFileHandle,
- 117 => CError.StructureNeedsCleaning,
- 118 => CError.NotAXENIXNamedTypeFile,
- 119 => CError.NoXENIXSemaphoresAvailable,
- 120 => CError.IsANamedTypeFile,
- 121 => CError.RemoteIOError,
- 122 => CError.DiskQuotaExceeded,
- 123 => CError.NoMediumFound,
- 124 => CError.WrongMediumType,
- 125 => CError.OperationCanceled,
- 126 => CError.RequiredKeyNotAvailable,
- 127 => CError.KeyHasExpired,
- 128 => CError.KeyHasBeenRevoked,
- 129 => CError.KeyWasRejectedByService,
- 130 => CError.OwnerDied,
- 131 => CError.StateNotRecoverable,
- 132 => CError.OperationNotPossibleDueToRFKill,
- 133 => CError.MemoryPageHasHardwareError,
- else => void{}
- };
+ const n = -@as(isize, @bitCast(errno));
+ return switch (n) {
+ 1 => CError.OperationNotPermitted,
+ 2 => CError.NoSuchFileOrDirectory,
+ 3 => CError.NoSuchProcess,
+ 4 => CError.InterruptedSystemCall,
+ 5 => CError.InputOutputError,
+ 6 => CError.NoSuchDeviceOrAddress,
+ 7 => CError.ArgumentListTooLong,
+ 8 => CError.ExecFormatError,
+ 9 => CError.BadFileDescriptor,
+ 10 => CError.NoChildProcesses,
+ 11 => CError.ResourceTemporarilyUnavailable,
+ 12 => CError.CannotAllocateMemory,
+ 13 => CError.PermissionDenied,
+ 14 => CError.BadAddress,
+ 15 => CError.BlockDeviceRequired,
+ 16 => CError.DeviceOrResourceBusy,
+ 17 => CError.FileExists,
+ 18 => CError.InvalidCrossDeviceLink,
+ 19 => CError.NoSuchDevice,
+ 20 => CError.NotADirectory,
+ 21 => CError.IsADirectory,
+ 22 => CError.InvalidArgument,
+ 23 => CError.TooManyOpenFilesInSystem,
+ 24 => CError.TooManyOpenFiles,
+ 25 => CError.InappropriateIoctlForDevice,
+ 26 => CError.TextFileBusy,
+ 27 => CError.FileTooLarge,
+ 28 => CError.NoSpaceLeftOnDevice,
+ 29 => CError.IllegalSeek,
+ 30 => CError.ReadOnlyFileSystem,
+ 31 => CError.TooManyLinks,
+ 32 => CError.BrokenPipe,
+ 33 => CError.NumericalArgumentOutOfDomain,
+ 34 => CError.NumericalResultOutOfRange,
+ 35 => CError.ResourceDeadlockAvoided,
+ 36 => CError.FileNameTooLong,
+ 37 => CError.NoLocksAvailable,
+ 38 => CError.FunctionNotImplemented,
+ 39 => CError.DirectoryNotEmpty,
+ 40 => CError.TooManyLevelsOfSymbolicLinks,
+ 42 => CError.NoMessageOfDesiredType,
+ 43 => CError.IdentifierRemoved,
+ 44 => CError.ChannelNumberOutOfRange,
+ 45 => CError.Level2NotSynchronized,
+ 46 => CError.Level3Halted,
+ 47 => CError.Level3Reset,
+ 48 => CError.LinkNumberOutOfRange,
+ 49 => CError.ProtocolDriverNotAttached,
+ 50 => CError.NoCSIStructureAvailable,
+ 51 => CError.Level2Halted,
+ 52 => CError.InvalidExchange,
+ 53 => CError.InvalidRequestDescriptor,
+ 54 => CError.ExchangeFull,
+ 55 => CError.NoAnode,
+ 56 => CError.InvalidRequestCode,
+ 57 => CError.InvalidSlot,
+ 59 => CError.BadFontFileFormat,
+ 60 => CError.DeviceNotAStream,
+ 61 => CError.NoDataAvailable,
+ 62 => CError.TimerExpired,
+ 63 => CError.OutOfStreamsResources,
+ 64 => CError.MachineIsNotOnTheNetwork,
+ 65 => CError.PackageNotInstalled,
+ 66 => CError.ObjectIsRemote,
+ 67 => CError.LinkHasBeenSevered,
+ 68 => CError.AdvertiseError,
+ 69 => CError.SrmountError,
+ 70 => CError.CommunicationErrorOnSend,
+ 71 => CError.ProtocolError,
+ 72 => CError.MultihopAttempted,
+ 73 => CError.RFSSpecificError,
+ 74 => CError.BadMessage,
+ 75 => CError.ValueTooLargeForDefinedDataType,
+ 76 => CError.NameNotUniqueOnNetwork,
+ 77 => CError.FileDescriptorInBadState,
+ 78 => CError.RemoteAddressChanged,
+ 79 => CError.CanNotAccessANeededSharedLibrary,
+ 80 => CError.AccessingACorruptedSharedLibrary,
+ 81 => CError.LibSectionInAOutCorrupted,
+ 82 => CError.AttemptingToLinkInTooManySharedLibraries,
+ 83 => CError.CannotExecASharedLibraryDirectly,
+ 84 => CError.InvalidOrIncompleteMultibyteOrWideCharacter,
+ 85 => CError.InterruptedSystemCallShouldBeRestarted,
+ 86 => CError.StreamsPipeError,
+ 87 => CError.TooManyUsers,
+ 88 => CError.SocketOperationOnNonSocket,
+ 89 => CError.DestinationAddressRequired,
+ 90 => CError.MessageTooLong,
+ 91 => CError.ProtocolWrongTypeForSocket,
+ 92 => CError.ProtocolNotAvailable,
+ 93 => CError.ProtocolNotSupported,
+ 94 => CError.SocketTypeNotSupported,
+ 95 => CError.OperationNotSupported,
+ 96 => CError.ProtocolFamilyNotSupported,
+ 97 => CError.AddressFamilyNotSupportedByProtocol,
+ 98 => CError.AddressAlreadyInUse,
+ 99 => CError.CannotAssignRequestedAddress,
+ 100 => CError.NetworkIsDown,
+ 101 => CError.NetworkIsUnreachable,
+ 102 => CError.NetworkDroppedConnectionOnReset,
+ 103 => CError.SoftwareCausedConnectionAbort,
+ 104 => CError.ConnectionResetByPeer,
+ 105 => CError.NoBufferSpaceAvailable,
+ 106 => CError.TransportEndpointIsAlreadyConnected,
+ 107 => CError.TransportEndpointIsNotConnected,
+ 108 => CError.CannotSendAfterTransportEndpointShutdown,
+ 109 => CError.TooManyReferences,
+ 110 => CError.ConnectionTimedOut,
+ 111 => CError.ConnectionRefused,
+ 112 => CError.HostIsDown,
+ 113 => CError.NoRouteToHost,
+ 114 => CError.OperationAlreadyInProgress,
+ 115 => CError.OperationNowInProgress,
+ 116 => CError.StaleFileHandle,
+ 117 => CError.StructureNeedsCleaning,
+ 118 => CError.NotAXENIXNamedTypeFile,
+ 119 => CError.NoXENIXSemaphoresAvailable,
+ 120 => CError.IsANamedTypeFile,
+ 121 => CError.RemoteIOError,
+ 122 => CError.DiskQuotaExceeded,
+ 123 => CError.NoMediumFound,
+ 124 => CError.WrongMediumType,
+ 125 => CError.OperationCanceled,
+ 126 => CError.RequiredKeyNotAvailable,
+ 127 => CError.KeyHasExpired,
+ 128 => CError.KeyHasBeenRevoked,
+ 129 => CError.KeyWasRejectedByService,
+ 130 => CError.OwnerDied,
+ 131 => CError.StateNotRecoverable,
+ 132 => CError.OperationNotPossibleDueToRFKill,
+ 133 => CError.MemoryPageHasHardwareError,
+ else => void{}
+};
}
diff --git a/src/screen/drm/card.zig b/src/screen/drm/card.zig
index 6147cf2..f1674bb 100644
--- a/src/screen/drm/card.zig
+++ b/src/screen/drm/card.zig
@@ -12,69 +12,69 @@ const Event = @import("event.zig").Event;
pub const Card = struct {
- const Self = @This();
+ const Self = @This();
- file: std.fs.File,
- allocator: std.mem.Allocator,
+ file: std.fs.File,
+ allocator: std.mem.Allocator,
- pub fn open(name: []const u8, allocator: std.mem.Allocator) !Self {
- var dri_dir = try std.fs.openDirAbsolute("/dev/dri", .{});
- defer dri_dir.close();
+ pub fn open(name: []const u8, allocator: std.mem.Allocator) !Self {
+ var dri_dir = try std.fs.openDirAbsolute("/dev/dri", .{});
+ defer dri_dir.close();
- return .{
- .file = try dri_dir.openFile(name, .{
- .mode = .read_write,
- .lock_nonblocking = true,
- }),
+ return .{
+ .file = try dri_dir.openFile(name, .{
+ .mode = .read_write,
+ .lock_nonblocking = true,
+ }),
- .allocator = allocator,
- };
- }
+ .allocator = allocator,
+ };
+ }
- pub fn close(self: *Card) void {
- self.file.close();
- }
+ pub fn close(self: *Card) void {
+ self.file.close();
+ }
- pub fn is_kms(self: *Card) !bool {
- const raw_info = Resources.raw_without_ids(self);
- return raw_info.count_crtcs > 0 and raw_info.count_connectors > 0 and raw_info.count_encoders > 0;
- }
+ pub fn is_kms(self: *Card) !bool {
+ const raw_info = Resources.raw_without_ids(self);
+ return raw_info.count_crtcs > 0 and raw_info.count_connectors > 0 and raw_info.count_encoders > 0;
+ }
- pub fn resources(self: *Card) !Resources {
- return Resources.init(self);
- }
+ pub fn resources(self: *Card) !Resources {
+ return Resources.init(self);
+ }
- pub fn connector(self: *Card, id: u32) !Connector {
- return Connector.init(self, id);
- }
+ pub fn connector(self: *Card, id: u32) !Connector {
+ return Connector.init(self, id);
+ }
- pub fn encoder(self: *Card, id: u32) !Encoder {
- return Encoder.init(self, id);
- }
+ pub fn encoder(self: *Card, id: u32) !Encoder {
+ return Encoder.init(self, id);
+ }
- pub fn crtc(self: *Card, id: u32) !Crtc {
- return Crtc.init(self, id);
- }
+ pub fn crtc(self: *Card, id: u32) !Crtc {
+ return Crtc.init(self, id);
+ }
- pub fn create_double_buffer(self: *Card, width: u32, height: u32, bpp: u32) !DoubleBuffer {
- return DoubleBuffer.init(self, width, height, bpp);
- }
+ pub fn create_double_buffer(self: *Card, width: u32, height: u32, bpp: u32) !DoubleBuffer {
+ return DoubleBuffer.init(self, width, height, bpp);
+ }
- pub fn poll_event(self: *Card, timeout: i32) !?Event {
- var pollfd = os.pollfd {
- .fd = self.file.handle,
- .events = os.POLL.IN,
- .revents = 0
- };
+ pub fn poll_event(self: *Card, timeout: i32) !?Event {
+ var pollfd = os.pollfd {
+ .fd = self.file.handle,
+ .events = os.POLL.IN,
+ .revents = 0
+ };
- try cerror.from_usize(os.poll(@ptrCast(&pollfd), 1, timeout));
+ try cerror.from_usize(os.poll(@ptrCast(&pollfd), 1, timeout));
- if ((pollfd.revents & os.POLL.IN) != 0) {
- var event = std.mem.zeroes(Event);
- try cerror.from_usize(os.read(self.file.handle, @ptrCast(&event), @sizeOf(Event)));
- return event;
- }
+ if ((pollfd.revents & os.POLL.IN) != 0) {
+ var event = std.mem.zeroes(Event);
+ try cerror.from_usize(os.read(self.file.handle, @ptrCast(&event), @sizeOf(Event)));
+ return event;
+ }
- return null;
- }
+ return null;
+ }
};
diff --git a/src/screen/drm/connector/connection.zig b/src/screen/drm/connector/connection.zig
index 9c4a8d8..7377800 100644
--- a/src/screen/drm/connector/connection.zig
+++ b/src/screen/drm/connector/connection.zig
@@ -1,6 +1,6 @@
pub const Connection = enum(u32) {
- undefined_state = 0,
- connected = 1,
- disconnected = 2,
- unknown = 3,
+ undefined_state = 0,
+ connected = 1,
+ disconnected = 2,
+ unknown = 3,
};
diff --git a/src/screen/drm/connector/mode.zig b/src/screen/drm/connector/mode.zig
index fb61b5b..1e28a23 100644
--- a/src/screen/drm/connector/mode.zig
+++ b/src/screen/drm/connector/mode.zig
@@ -1,70 +1,70 @@
pub const Mode = extern struct {
- const Self = @This();
+ const Self = @This();
- const DimensionInfo = extern struct {
- const Sync = extern struct { start: u16, end: u16 };
+ const DimensionInfo = extern struct {
+ const Sync = extern struct { start: u16, end: u16 };
- size: u16,
- sync: Sync,
- total: u16,
- };
+ size: u16,
+ sync: Sync,
+ total: u16,
+};
- const Type = packed struct(u32) {
- builtin: bool,
- clock_c: bool,
- crtc_c: bool,
- preferred: bool,
- default: bool,
- userdef: bool,
- driver: bool,
- _padding: u25,
- };
+const Type = packed struct(u32) {
+ builtin: bool,
+ clock_c: bool,
+ crtc_c: bool,
+ preferred: bool,
+ default: bool,
+ userdef: bool,
+ driver: bool,
+ _padding: u25,
+};
- const Flags = packed struct(u32) {
- phsync: bool,
- nhsync: bool,
- pvsync: bool,
- nvsync: bool,
- interlace: bool,
- dblscan: bool,
- csync: bool,
- pcsync: bool,
- ncsync: bool,
- hskew: bool,
- bcast: bool,
- pixmux: bool,
- dblclk: bool,
- clkdiv2: bool,
- _padding: u18,
- };
+const Flags = packed struct(u32) {
+ phsync: bool,
+ nhsync: bool,
+ pvsync: bool,
+ nvsync: bool,
+ interlace: bool,
+ dblscan: bool,
+ csync: bool,
+ pcsync: bool,
+ ncsync: bool,
+ hskew: bool,
+ bcast: bool,
+ pixmux: bool,
+ dblclk: bool,
+ clkdiv2: bool,
+ _padding: u18,
+ };
- clock: u32,
- horizontal: DimensionInfo,
- skew: u16,
- vertical: DimensionInfo,
- line_scans: u16,
- vertical_refresh: u32,
+clock: u32,
+ horizontal: DimensionInfo,
+ skew: u16,
+ vertical: DimensionInfo,
+ line_scans: u16,
+ vertical_refresh: u32,
- flags: Flags,
- type: Type,
- name: [32]u8,
+ flags: Flags,
+ type: Type,
+ name: [32]u8,
- pub fn frame_rate(self: *const Self) f32 {
- var rate = (@as(u64, @intCast(self.clock)) * 1000000 / self.horizontal.total + self.vertical.total / 2) / self.vertical.total;
+ pub fn frame_rate(self: *const Self) f32 {
+ var rate = (@as(u64, @intCast(self.clock)) * 1000000 / self.horizontal.total + self.vertical.total / 2) / self.vertical.total;
- if (self.flags.interlace) {
- rate *= 2;
- }
+ if (self.flags.interlace) {
+ rate *= 2;
+ }
- if (self.flags.dblscan) {
- rate /= 2;
- }
+ if (self.flags.dblscan) {
+ rate /= 2;
+ }
- if (self.line_scans > 1) {
- rate /= self.line_scans;
- }
+ if (self.line_scans > 1) {
+ rate /= self.line_scans;
+ }
- return @as(f32, @floatFromInt(rate)) / 1000.0;
- }
+ return @as(f32, @floatFromInt(rate)) / 1000.0;
+ }
};
diff --git a/src/screen/drm/connector/root.zig b/src/screen/drm/connector/root.zig
index c104e84..6141899 100644
--- a/src/screen/drm/connector/root.zig
+++ b/src/screen/drm/connector/root.zig
@@ -9,89 +9,104 @@ pub const Mode = @import("mode.zig").Mode;
pub const ConnectorType = @import("type.zig").Type;
const RawConnector = extern struct {
- encoder_ids: ?*u32,
- modes: ?*Mode,
- prop_ids: ?*u32,
- prop_value_ids: ?*u64,
- count_modes: u32,
- count_props: u32,
- count_encoders: u32,
- encoder_id: u32,
- id: u32,
- type: ConnectorType,
- type_id: u32,
- connection: Connection,
- mm_width: u32,
- mm_height: u32,
- subpixel: u32,
- pad: u32,
+ encoder_ids: ?*u32,
+ modes: ?*Mode,
+ prop_ids: ?*u32,
+ prop_value_ids: ?*u64,
+ count_modes: u32,
+ count_props: u32,
+ count_encoders: u32,
+ encoder_id: u32,
+ id: u32,
+ type: ConnectorType,
+ type_id: u32,
+ connection: Connection,
+ mm_width: u32,
+ mm_height: u32,
+ subpixel: u32,
+ pad: u32,
};
pub const Connector = struct {
- const Self = @This();
+ const Self = @This();
- card: *Card,
+ card: *Card,
- encoder_ids: []u32,
- modes: []Mode,
- prop_ids: []u32,
- prop_value_ids: []u64,
- encoder_id: u32,
- id: u32,
- type: ConnectorType,
- type_id: u32,
- connection: Connection,
- mm_width: u32,
- mm_height: u32,
- subpixel: u32,
- pad: u32,
+ encoder_ids: []u32,
+ modes: []Mode,
+ prop_ids: []u32,
+ prop_value_ids: []u64,
+ encoder_id: u32,
+ id: u32,
+ type: ConnectorType,
+ type_id: u32,
+ connection: Connection,
+ mm_width: u32,
+ mm_height: u32,
+ subpixel: u32,
+ pad: u32,
- pub fn raw_without_ids(card: *Card, id: u32) !RawConnector {
- var result = std.mem.zeroInit(RawConnector, .{ .id = id });
- try Drm.get_connector.request(card.file.handle, RawConnector, &result);
- return result;
- }
+ pub fn raw_without_ids(card: *Card, id: u32) !RawConnector {
+ var result = std.mem.zeroInit(RawConnector, .{ .id = id });
+ try Drm.get_connector.request(card.file.handle, RawConnector, &result);
+ return result;
+ }
- // NOTE: This function does not take in account
- // that there might be some hot-plugging going
- // on. This might have to change in the future.
- pub fn init(card: *Card, id: u32) !Self {
- var raw = try Self.raw_without_ids(card, id);
- const resources = .{
- .encoder_ids = try card.allocator.alloc(u32, raw.count_encoders),
- .modes = try card.allocator.alloc(Mode, raw.count_modes),
- .prop_ids = try card.allocator.alloc(u32, raw.count_props),
- .prop_value_ids = try card.allocator.alloc(u64, raw.count_props),
- .encoder_id = raw.encoder_id,
- .id = raw.id,
- .type = raw.type,
- .type_id = raw.type_id,
- .connection = raw.connection,
- .mm_width = raw.mm_width,
- .mm_height = raw.mm_height,
- .subpixel = raw.subpixel,
- .pad = raw.pad,
- .card = card,
- };
+ // NOTE: This function does not take in account
+ // that there might be some hot-plugging going
+ // on. This might have to change in the future.
+ pub fn init(card: *Card, id: u32) !Self {
+ var raw = try Self.raw_without_ids(card, id);
+ const resources = .{
+ .encoder_ids = try card.allocator.alloc(u32, raw.count_encoders),
+ .modes = try card.allocator.alloc(Mode, raw.count_modes),
+ .prop_ids = try card.allocator.alloc(u32, raw.count_props),
+ .prop_value_ids = try card.allocator.alloc(u64, raw.count_props),
+ .encoder_id = raw.encoder_id,
+ .id = raw.id,
+ .type = raw.type,
+ .type_id = raw.type_id,
+ .connection = raw.connection,
+ .mm_width = raw.mm_width,
+ .mm_height = raw.mm_height,
+ .subpixel = raw.subpixel,
+ .pad = raw.pad,
+ .card = card,
+ };
- @memset(resources.encoder_ids, 0);
- @memset(resources.modes, std.mem.zeroes(Mode));
- @memset(resources.prop_ids, 0);
- @memset(resources.prop_value_ids, 0);
+ @memset(resources.encoder_ids, 0);
+ @memset(resources.modes, std.mem.zeroes(Mode));
+ @memset(resources.prop_ids, 0);
+ @memset(resources.prop_value_ids, 0);
- raw.encoder_ids = @ptrCast(resources.encoder_ids);
- raw.modes = @ptrCast(resources.modes);
- raw.prop_ids = @ptrCast(resources.prop_ids);
- raw.prop_value_ids = @ptrCast(resources.prop_value_ids);
+ raw.encoder_ids = @ptrCast(resources.encoder_ids);
+ raw.modes = @ptrCast(resources.modes);
+ raw.prop_ids = @ptrCast(resources.prop_ids);
+ raw.prop_value_ids = @ptrCast(resources.prop_value_ids);
- try Drm.get_connector.request(card.file.handle, RawConnector, &raw);
+ try Drm.get_connector.request(card.file.handle, RawConnector, &raw);
- return resources;
- }
+ return resources;
+ }
- pub fn deinit(self: *Self) void {
- self.card.allocator.free(self.encoder_ids);
- self.card.allocator.free(self.modes);
- self.card.allocator.free(self.prop_ids);
- }
+ pub fn deinit(self: *Self) void {
+ self.card.allocator.free(self.encoder_ids);
+ self.card.allocator.free(self.modes);
+ self.card.allocator.free(self.prop_ids);
+ }
+
+ pub fn compatible_crtc(self: *Self) ?usize {
+ for (self.encoder_ids) |encoder_id| {
+ var encoder = self.card.encoder(encoder_id) catch continue;
+ defer encoder.deinit();
+
+ for (0..32) |index| {
+ if ((encoder.possible_crtcs & (@as(u32, 1) << @intCast(index))) != 0) {
+ return index;
+ }
+ }
+ }
+
+ return null;
+ }
};
diff --git a/src/screen/drm/connector/type.zig b/src/screen/drm/connector/type.zig
index 15db753..c813c66 100644
--- a/src/screen/drm/connector/type.zig
+++ b/src/screen/drm/connector/type.zig
@@ -1,23 +1,23 @@
pub const Type = enum(u32) {
- unknown = 0,
- vga = 1,
- dvi_i = 2,
- dvi_d = 3,
- dvi_a = 4,
- composite = 5,
- s_video = 6,
- lvds = 7,
- component = 8,
- nine_pin_din = 9,
- display_port = 10,
- hdmi_a = 11,
- hdmi_b = 12,
- tv = 13,
- edp = 14,
- virtual = 15,
- dsi = 16,
- dpi = 17,
- writeback = 18,
- spi = 19,
- usb = 20,
+ unknown = 0,
+ vga = 1,
+ dvi_i = 2,
+ dvi_d = 3,
+ dvi_a = 4,
+ composite = 5,
+ s_video = 6,
+ lvds = 7,
+ component = 8,
+ nine_pin_din = 9,
+ display_port = 10,
+ hdmi_a = 11,
+ hdmi_b = 12,
+ tv = 13,
+ edp = 14,
+ virtual = 15,
+ dsi = 16,
+ dpi = 17,
+ writeback = 18,
+ spi = 19,
+ usb = 20,
};
diff --git a/src/screen/drm/crtc/root.zig b/src/screen/drm/crtc/root.zig
index f1f1d5c..bbb72cb 100644
--- a/src/screen/drm/crtc/root.zig
+++ b/src/screen/drm/crtc/root.zig
@@ -8,112 +8,112 @@ const DoubleBuffer = fb.DoubleBuffer;
const Mode = @import("../connector/mode.zig").Mode;
pub const RawCrtc = extern struct {
- connector_ids: ?*u32,
- count_connectors: u32,
- id: u32,
- buffer_id: u32,
- x: u32,
- y: u32,
- gamma_size: u32,
- mode_valid: u32,
- mode: Mode,
+ connector_ids: ?*u32,
+ count_connectors: u32,
+ id: u32,
+ buffer_id: u32,
+ x: u32,
+ y: u32,
+ gamma_size: u32,
+ mode_valid: u32,
+ mode: Mode,
};
const PageFlipEvent = packed struct(u32) {
- event: bool,
- is_async: bool,
- absolute: bool,
- relative: bool,
- __padding: u28,
+ event: bool,
+ is_async: bool,
+ absolute: bool,
+ relative: bool,
+ __padding: u28,
};
const PageFlip = extern struct {
- crtc_id: u32,
- buffer_id: u32,
- flags: PageFlipEvent,
- __reserved: u32,
- user_data: u64,
+ crtc_id: u32,
+ buffer_id: u32,
+ flags: PageFlipEvent,
+ __reserved: u32,
+ user_data: u64,
};
pub const Crtc = struct {
- const Self = @This();
+ const Self = @This();
- connector_ids: ?*u32,
- count_connectors: u32,
- id: u32,
- buffer_id: u32,
- x: u32,
- y: u32,
- mode: Mode,
- mode_valid: u32,
- gamma_size: u32,
- card: *Card,
+ connector_ids: ?*u32,
+ count_connectors: u32,
+ id: u32,
+ buffer_id: u32,
+ x: u32,
+ y: u32,
+ mode: Mode,
+ mode_valid: u32,
+ gamma_size: u32,
+ card: *Card,
- pub fn init(card: *Card, id: u32) !Self {
- var raw = std.mem.zeroInit(RawCrtc, .{ .id = id });
- try Drm.get_crtc.request(card.file.handle, RawCrtc, &raw);
- return .{
- .connector_ids = raw.connector_ids,
- .count_connectors = raw.count_connectors,
- .id = raw.id,
- .buffer_id = raw.buffer_id,
- .x = raw.x,
- .y = raw.y,
- .mode = raw.mode,
- .mode_valid = raw.mode_valid,
- .gamma_size = raw.gamma_size,
- .card = card,
- };
- }
+ pub fn init(card: *Card, id: u32) !Self {
+ var raw = std.mem.zeroInit(RawCrtc, .{ .id = id });
+ try Drm.get_crtc.request(card.file.handle, RawCrtc, &raw);
+ return .{
+ .connector_ids = raw.connector_ids,
+ .count_connectors = raw.count_connectors,
+ .id = raw.id,
+ .buffer_id = raw.buffer_id,
+ .x = raw.x,
+ .y = raw.y,
+ .mode = raw.mode,
+ .mode_valid = raw.mode_valid,
+ .gamma_size = raw.gamma_size,
+ .card = card,
+ };
+ }
- pub fn attach(self: *Self, frame_buffer: *FrameBuffer, connector: *Connector, mode: Mode) !void {
- self.connector_ids = &connector.id;
- self.count_connectors = 1;
+ pub fn attach(self: *Self, frame_buffer: *FrameBuffer, connector: *Connector, mode: Mode) !void {
+ self.connector_ids = &connector.id;
+ self.count_connectors = 1;
- var crtc = RawCrtc {
- .id = self.id,
- .x = self.x,
- .y = self.y,
- .buffer_id = frame_buffer.id,
- .connector_ids = self.connector_ids,
- .count_connectors = self.count_connectors,
- .mode = mode,
- .mode_valid = 1,
- .gamma_size = self.gamma_size,
- };
+ var crtc = RawCrtc {
+ .id = self.id,
+ .x = self.x,
+ .y = self.y,
+ .buffer_id = frame_buffer.id,
+ .connector_ids = self.connector_ids,
+ .count_connectors = self.count_connectors,
+ .mode = mode,
+ .mode_valid = 1,
+ .gamma_size = self.gamma_size,
+ };
- try Drm.set_crtc.request(self.card.file.handle, RawCrtc, &crtc);
- }
+ try Drm.set_crtc.request(self.card.file.handle, RawCrtc, &crtc);
+ }
- pub fn page_flip(self: *Self, double_buffer: *DoubleBuffer) !void {
- double_buffer.swap();
+ pub fn page_flip(self: *Self, double_buffer: *DoubleBuffer) !void {
+ double_buffer.swap();
- var flip = std.mem.zeroInit(PageFlip, .{
- .buffer_id = double_buffer.crtc_buffer().id,
- .crtc_id = self.id,
- .flags = std.mem.zeroInit(PageFlipEvent, .{ .event = true }),
- });
+ var flip = std.mem.zeroInit(PageFlip, .{
+ .buffer_id = double_buffer.crtc_buffer().id,
+ .crtc_id = self.id,
+ .flags = std.mem.zeroInit(PageFlipEvent, .{ .event = true }),
+ });
- try Drm.page_flip.request(self.card.file.handle, PageFlip, &flip);
- }
+ try Drm.page_flip.request(self.card.file.handle, PageFlip, &flip);
+ }
- pub fn detach(self: *Self) void {
- var crtc = RawCrtc {
- .id = self.id,
- .x = self.x,
- .y = self.y,
- .buffer_id = self.buffer_id,
- .connector_ids = self.connector_ids,
- .count_connectors = self.count_connectors,
- .mode = self.mode,
- .mode_valid = self.mode_valid,
- .gamma_size = self.gamma_size,
- };
+ pub fn detach(self: *Self) void {
+ var crtc = RawCrtc {
+ .id = self.id,
+ .x = self.x,
+ .y = self.y,
+ .buffer_id = self.buffer_id,
+ .connector_ids = self.connector_ids,
+ .count_connectors = self.count_connectors,
+ .mode = self.mode,
+ .mode_valid = self.mode_valid,
+ .gamma_size = self.gamma_size,
+ };
- Drm.set_crtc.request(
- self.card.file.handle,
- RawCrtc,
- &crtc
- ) catch |err| std.debug.panic("set crtc failed on detach: {}", .{err});
- }
+ Drm.set_crtc.request(
+ self.card.file.handle,
+ RawCrtc,
+ &crtc
+ ) catch |err| std.debug.panic("set crtc failed on detach: {}", .{err});
+ }
};
diff --git a/src/screen/drm/encoder/root.zig b/src/screen/drm/encoder/root.zig
index 0712c76..7b8932a 100644
--- a/src/screen/drm/encoder/root.zig
+++ b/src/screen/drm/encoder/root.zig
@@ -5,36 +5,36 @@ const Card = @import("../card.zig").Card;
const Type = @import("type.zig").Type;
pub const RawEncoder = extern struct {
- id: u32,
- type: Type,
- crtc_id: u32,
- possible_crtcs: u32,
- possible_clones: u32,
+ id: u32,
+ type: Type,
+ crtc_id: u32,
+ possible_crtcs: u32,
+ possible_clones: u32,
};
pub const Encoder = struct {
- const Self = @This();
+ const Self = @This();
- id: u32,
- type: Type,
- possible_crtcs: u32,
- possible_clones: u32,
- card: *Card,
+ id: u32,
+ type: Type,
+ possible_crtcs: u32,
+ possible_clones: u32,
+ card: *Card,
- pub fn init(card: *Card, id: u32) !Self {
- var raw = std.mem.zeroInit(RawEncoder, .{ .id = id });
- try Drm.get_encoder.request(card.file.handle, RawEncoder, &raw);
+ pub fn init(card: *Card, id: u32) !Self {
+ var raw = std.mem.zeroInit(RawEncoder, .{ .id = id });
+ try Drm.get_encoder.request(card.file.handle, RawEncoder, &raw);
- return .{
- .id = raw.id,
- .type = raw.type,
- .possible_crtcs = raw.possible_crtcs,
- .possible_clones = raw.possible_clones,
- .card = card
- };
- }
+ return .{
+ .id = raw.id,
+ .type = raw.type,
+ .possible_crtcs = raw.possible_crtcs,
+ .possible_clones = raw.possible_clones,
+ .card = card
+ };
+ }
- pub fn deinit(self: *Self) void {
- _ = self;
- }
+ pub fn deinit(self: *Self) void {
+ _ = self;
+ }
};
diff --git a/src/screen/drm/encoder/type.zig b/src/screen/drm/encoder/type.zig
index a26dc9c..12246d2 100644
--- a/src/screen/drm/encoder/type.zig
+++ b/src/screen/drm/encoder/type.zig
@@ -1,11 +1,11 @@
pub const Type = enum(u32) {
- none = 0,
- dac = 1,
- tmds = 2,
- lvds = 3,
- tvdac = 4,
- virtual = 5,
- dsi = 6,
- dpmst = 7,
- dpi = 8,
+ none = 0,
+ dac = 1,
+ tmds = 2,
+ lvds = 3,
+ tvdac = 4,
+ virtual = 5,
+ dsi = 6,
+ dpmst = 7,
+ dpi = 8,
};
diff --git a/src/screen/drm/event.zig b/src/screen/drm/event.zig
index 201ced3..d60af57 100644
--- a/src/screen/drm/event.zig
+++ b/src/screen/drm/event.zig
@@ -1,31 +1,31 @@
pub const EventType = enum(u32) {
- vblank = 1,
- page_flip_complete = 2,
- crtc_sequence = 3,
+ vblank = 1,
+ page_flip_complete = 2,
+ crtc_sequence = 3,
};
pub const VBlankEvent = extern struct {
- user_data: u64,
- tv_sec: u32,
- tv_usec: u32,
- sequence: u32,
- crtc_id: u32,
+ user_data: u64,
+ tv_sec: u32,
+ tv_usec: u32,
+ sequence: u32,
+ crtc_id: u32,
};
pub const CrtcSequenceEvent = extern struct {
- user_data: u64,
- time_ns: i64,
- sequence: u64,
+ user_data: u64,
+ time_ns: i64,
+ sequence: u64,
};
pub const EventPayload = extern union {
- vblank: VBlankEvent,
- crtc_sequence: CrtcSequenceEvent,
+ vblank: VBlankEvent,
+ crtc_sequence: CrtcSequenceEvent,
};
pub const Event = extern struct {
- type: EventType,
- length: u32,
- payload: EventPayload,
+ type: EventType,
+ length: u32,
+ payload: EventPayload,
};
diff --git a/src/screen/drm/frame-buffer/page-flip.zig b/src/screen/drm/frame-buffer/page-flip.zig
index 2e41e61..c6eb836 100644
--- a/src/screen/drm/frame-buffer/page-flip.zig
+++ b/src/screen/drm/frame-buffer/page-flip.zig
@@ -1,8 +1,7 @@
-
pub const PageFlip = packed struct(u32) {
- event: bool,
- is_async: bool,
- absolute: bool,
- relative: bool,
- _padding: u28,
+ event: bool,
+ is_async: bool,
+ absolute: bool,
+ relative: bool,
+ _padding: u28,
}
diff --git a/src/screen/drm/frame-buffer/pixelformat.zig b/src/screen/drm/frame-buffer/pixelformat.zig
index a4b3f9a..ec98900 100644
--- a/src/screen/drm/frame-buffer/pixelformat.zig
+++ b/src/screen/drm/frame-buffer/pixelformat.zig
@@ -1,11 +1,11 @@
fn pixel_format_code(comptime a: u8, comptime b: u8, comptime c: u8, comptime d: u8) u32 {
- return @as(u32, @intCast(a)) |
- (@as(u32, @intCast(b)) << 8) |
- (@as(u32, @intCast(c)) << 16) |
- (@as(u32, @intCast(d)) << 24);
+ return @as(u32, @intCast(a)) |
+ (@as(u32, @intCast(b)) << 8) |
+ (@as(u32, @intCast(c)) << 16) |
+ (@as(u32, @intCast(d)) << 24);
}
pub const PixelFormat = enum(u32) {
- xrgb8888 = pixel_format_code('X', 'R', '2', '4'),
+ xrgb8888 = pixel_format_code('X', 'R', '2', '4'),
};
diff --git a/src/screen/drm/frame-buffer/root.zig b/src/screen/drm/frame-buffer/root.zig
index 0083711..e0e51f8 100644
--- a/src/screen/drm/frame-buffer/root.zig
+++ b/src/screen/drm/frame-buffer/root.zig
@@ -6,183 +6,183 @@ const PixelFormat = @import("pixelformat.zig").PixelFormat;
const cerror = @import("../../cerror.zig");
const CreateDumb = extern struct {
- height: u32,
- width: u32,
- bpp: u32,
- flags: u32,
- handle: u32,
- pitch: u32,
- size: u32,
+ height: u32,
+ width: u32,
+ bpp: u32,
+ flags: u32,
+ handle: u32,
+ pitch: u32,
+ size: u32,
};
const FrameBufferCmd2 = extern struct {
- id: u32,
- width: u32,
- height: u32,
- pixel_format: PixelFormat,
- flags: u32,
- handles: [4]u32,
- pitches: [4]u32,
- offsets: [4]u32,
- modifier: [4]u32,
+ id: u32,
+ width: u32,
+ height: u32,
+ pixel_format: PixelFormat,
+ flags: u32,
+ handles: [4]u32,
+ pitches: [4]u32,
+ offsets: [4]u32,
+ modifier: [4]u32,
};
const MapDumb = extern struct {
- handle: u32,
- __padding: u32,
- offset: i64,
+ handle: u32,
+ __padding: u32,
+ offset: i64,
};
pub const DoubleBuffer = struct {
- const Self = @This();
+ const Self = @This();
- back: FrameBuffer,
- front: FrameBuffer,
+ back: FrameBuffer,
+ front: FrameBuffer,
- pub fn init(card: *Card, width: u32, height: u32, bpp: u32) !Self {
- return .{
- .back = try FrameBuffer.init(card, width, height, bpp),
- .front = try FrameBuffer.init(card, width, height, bpp),
- };
- }
+ pub fn init(card: *Card, width: u32, height: u32, bpp: u32) !Self {
+ return .{
+ .back = try FrameBuffer.init(card, width, height, bpp),
+ .front = try FrameBuffer.init(card, width, height, bpp),
+ };
+ }
- pub fn swap(self: *Self) void {
- const back_data = self.back.data;
- self.back.data = self.front.data;
- self.front.data = back_data;
+ pub fn swap(self: *Self) void {
+ const back_data = self.back.data;
+ self.back.data = self.front.data;
+ self.front.data = back_data;
- const back_id = self.back.id;
- self.back.id = self.front.id;
- self.front.id = back_id;
- }
+ const back_id = self.back.id;
+ self.back.id = self.front.id;
+ self.front.id = back_id;
+ }
- pub fn deinit(self: *Self) void {
- self.back.deinit();
- self.front.deinit();
- }
+ pub fn deinit(self: *Self) void {
+ self.back.deinit();
+ self.front.deinit();
+ }
- pub fn buffer(self: *Self) *FrameBuffer {
- return &self.back;
- }
+ pub fn buffer(self: *Self) *FrameBuffer {
+ return &self.back;
+ }
- pub fn crtc_buffer(self: *Self) *FrameBuffer {
- return &self.front;
- }
+ pub fn crtc_buffer(self: *Self) *FrameBuffer {
+ return &self.front;
+ }
};
pub const Pixel = packed struct(u32) {
- blue: u8,
- green: u8,
- red: u8,
- _padding: u8 = 0x0,
+ blue: u8,
+ green: u8,
+ red: u8,
+ _padding: u8 = 0x0,
};
pub const FrameBuffer = struct {
- const Self = @This();
+ const Self = @This();
- card: *Card,
- id: u32,
- width: u32,
- height: u32,
- bpp: u32,
- stride: u32,
- data_size: u64,
- canvas_size: u64,
- handle: u32,
- data: [*]volatile Pixel,
+ card: *Card,
+ id: u32,
+ width: u32,
+ height: u32,
+ bpp: u32,
+ stride: u32,
+ data_size: u64,
+ canvas_size: u64,
+ handle: u32,
+ data: [*]volatile Pixel,
- pub fn init(card: *Card, width: u32, height: u32, bpp: u32) !Self {
- var create_dumb = std.mem.zeroInit(CreateDumb, .{
- .width = width,
- .height = height,
- .bpp = bpp,
- });
- try Drm.create_dumb.request(
- card.file.handle,
- CreateDumb,
- &create_dumb
- );
+ pub fn init(card: *Card, width: u32, height: u32, bpp: u32) !Self {
+ var create_dumb = std.mem.zeroInit(CreateDumb, .{
+ .width = width,
+ .height = height,
+ .bpp = bpp,
+ });
+ try Drm.create_dumb.request(
+ card.file.handle,
+ CreateDumb,
+ &create_dumb
+ );
- var fb = Self {
- .id = 0,
- .width = create_dumb.width,
- .height = create_dumb.height,
- .bpp = create_dumb.bpp,
- .stride = create_dumb.pitch,
- .data_size = create_dumb.size,
- .canvas_size = create_dumb.size / (bpp / 8),
- .handle = create_dumb.handle,
- .data = undefined,
- .card = card,
- };
+ var fb = Self {
+ .id = 0,
+ .width = create_dumb.width,
+ .height = create_dumb.height,
+ .bpp = create_dumb.bpp,
+ .stride = create_dumb.pitch,
+ .data_size = create_dumb.size,
+ .canvas_size = create_dumb.size / (bpp / 8),
+ .handle = create_dumb.handle,
+ .data = undefined,
+ .card = card,
+ };
- var buffer_cmd = FrameBufferCmd2 {
- .id = 0,
- .width = fb.width,
- .height = fb.height,
- .pixel_format = PixelFormat.xrgb8888,
- .flags = 0,
- .handles = [_] u32 { fb.handle, 0, 0, 0 },
- .pitches = [_] u32 { fb.stride, 0, 0, 0 },
- .offsets = [_] u32 { 0, 0, 0, 0 },
- .modifier = [_] u32 { 0, 0, 0, 0 },
- };
+ var buffer_cmd = FrameBufferCmd2 {
+ .id = 0,
+ .width = fb.width,
+ .height = fb.height,
+ .pixel_format = PixelFormat.xrgb8888,
+ .flags = 0,
+ .handles = [_] u32 { fb.handle, 0, 0, 0 },
+ .pitches = [_] u32 { fb.stride, 0, 0, 0 },
+ .offsets = [_] u32 { 0, 0, 0, 0 },
+ .modifier = [_] u32 { 0, 0, 0, 0 },
+ };
- try Drm.add_frame_buffer2.request(
- card.file.handle,
- FrameBufferCmd2,
- &buffer_cmd
- );
+ try Drm.add_frame_buffer2.request(
+ card.file.handle,
+ FrameBufferCmd2,
+ &buffer_cmd
+ );
- fb.id = buffer_cmd.id;
+ fb.id = buffer_cmd.id;
- var map_dumb = std.mem.zeroInit(MapDumb, .{ .handle = fb.handle });
+ var map_dumb = std.mem.zeroInit(MapDumb, .{ .handle = fb.handle });
- try Drm.map_dumb.request(
- card.file.handle,
- MapDumb,
- &map_dumb
- );
+ try Drm.map_dumb.request(
+ card.file.handle,
+ MapDumb,
+ &map_dumb
+ );
- const address = os.mmap(
- null,
- fb.data_size,
- os.PROT.READ | os.PROT.WRITE,
- .{ .TYPE = os.MAP_TYPE.SHARED },
- card.file.handle,
- map_dumb.offset
- );
+ const address = os.mmap(
+ null,
+ fb.data_size,
+ os.PROT.READ | os.PROT.WRITE,
+ .{ .TYPE = os.MAP_TYPE.SHARED },
+ card.file.handle,
+ map_dumb.offset
+ );
- try cerror.from_usize(address);
+ try cerror.from_usize(address);
- fb.data = @ptrFromInt(address);
+ fb.data = @ptrFromInt(address);
- return fb;
- }
+ return fb;
+ }
- pub fn set(self: *Self, x: u32, y: u32, pixel: Pixel) void {
- self.data[x + self.width * y] = pixel;
- }
+ pub fn set(self: *Self, x: u32, y: u32, pixel: Pixel) void {
+ self.data[x + self.width * y] = pixel;
+ }
- pub fn fill(self: *Self, pixel: Pixel) void {
- @memset(self.data[0..self.canvas_size], pixel);
- }
+ pub fn fill(self: *Self, pixel: Pixel) void {
+ @memset(self.data[0..self.canvas_size], pixel);
+ }
- pub fn deinit(self: *Self) void {
- cerror.from_usize(
- os.munmap(@ptrCast(@volatileCast(self.data)), self.data_size)
- ) catch |err| std.debug.panic("munmap failed in frame-buffer: {}", .{err});
+ pub fn deinit(self: *Self) void {
+ cerror.from_usize(
+ os.munmap(@ptrCast(@volatileCast(self.data)), self.data_size)
+ ) catch |err| std.debug.panic("munmap failed in frame-buffer: {}", .{err});
- Drm.remove_frame_buffer.request(
- self.card.file.handle,
- u32,
- &self.id
- ) catch @panic("failed to remove frame-buffer");
+ Drm.remove_frame_buffer.request(
+ self.card.file.handle,
+ u32,
+ &self.id
+ ) catch @panic("failed to remove frame-buffer");
- Drm.destroy_dumb.request(
- self.card.file.handle,
- u32,
- &self.handle
- ) catch @panic("failed to destroy dumb-buffer");
- }
+ Drm.destroy_dumb.request(
+ self.card.file.handle,
+ u32,
+ &self.handle
+ ) catch @panic("failed to destroy dumb-buffer");
+ }
};
diff --git a/src/screen/drm/request.zig b/src/screen/drm/request.zig
index 5daf92f..9a70c7d 100644
--- a/src/screen/drm/request.zig
+++ b/src/screen/drm/request.zig
@@ -3,27 +3,27 @@ const os = std.os.linux;
const cerror = @import("../cerror.zig");
fn ioctl(fd: os.fd_t, request: u32, arg: usize) !void {
- try cerror.from_usize(os.ioctl(fd, request, arg));
+ try cerror.from_usize(os.ioctl(fd, request, arg));
}
pub const Drm = enum(u8) {
- const Self = @This();
+ const Self = @This();
- get_resources = 0xa0,
- get_crtc = 0xa1,
- set_crtc = 0xa2,
- get_encoder = 0xa6,
- get_connector = 0xa7,
- remove_frame_buffer = 0xaf,
- page_flip = 0xb0,
- dirty_frame_buffer = 0xb1,
- create_dumb = 0xb2,
- map_dumb = 0xb3,
- destroy_dumb = 0xb4,
- add_frame_buffer2 = 0xb8,
+ get_resources = 0xa0,
+ get_crtc = 0xa1,
+ set_crtc = 0xa2,
+ get_encoder = 0xa6,
+ get_connector = 0xa7,
+ remove_frame_buffer = 0xaf,
+ page_flip = 0xb0,
+ dirty_frame_buffer = 0xb1,
+ create_dumb = 0xb2,
+ map_dumb = 0xb3,
+ destroy_dumb = 0xb4,
+ add_frame_buffer2 = 0xb8,
- pub fn request(self: Self, fd: os.fd_t, T: type, arg: *T) !void {
- const id = os.IOCTL.IOWR('d', @intFromEnum(self), T);
- try ioctl(fd, id, @intFromPtr(arg));
- }
+ pub fn request(self: Self, fd: os.fd_t, T: type, arg: *T) !void {
+ const id = os.IOCTL.IOWR('d', @intFromEnum(self), T);
+ try ioctl(fd, id, @intFromPtr(arg));
+ }
};
diff --git a/src/screen/drm/resources.zig b/src/screen/drm/resources.zig
index 6128f37..fdd5042 100644
--- a/src/screen/drm/resources.zig
+++ b/src/screen/drm/resources.zig
@@ -5,72 +5,72 @@ const Card = @import("card.zig").Card;
const Drm = @import("request.zig").Drm;
const RawResources = extern struct {
- fb_ids: ?*u32,
- crtc_ids: ?*u32,
- connector_ids: ?*u32,
- encoder_ids: ?*u32,
- count_fbs: u32,
- count_crtcs: u32,
- count_connectors: u32,
- count_encoders: u32,
- min_width: u32,
- max_width: u32,
- min_height: u32,
- max_height: u32,
+ fb_ids: ?*u32,
+ crtc_ids: ?*u32,
+ connector_ids: ?*u32,
+ encoder_ids: ?*u32,
+ count_fbs: u32,
+ count_crtcs: u32,
+ count_connectors: u32,
+ count_encoders: u32,
+ min_width: u32,
+ max_width: u32,
+ min_height: u32,
+ max_height: u32,
};
pub const Resources = struct {
- const Self = @This();
- const Range = struct { min: u32, max: u32 };
+ const Self = @This();
+ const Range = struct { min: u32, max: u32 };
- card: *Card,
+ card: *Card,
- fb_ids: []u32,
- crtc_ids: []u32,
- connector_ids: []u32,
- encoder_ids: []u32,
- width: Range,
- height: Range,
+ fb_ids: []u32,
+ crtc_ids: []u32,
+ connector_ids: []u32,
+ encoder_ids: []u32,
+ width: Range,
+ height: Range,
- pub fn raw_without_ids(card: *Card) !RawResources {
- var result = std.mem.zeroes(RawResources);
- try Drm.get_resources.request(card.file.handle, RawResources, &result);
- return result;
- }
+ pub fn raw_without_ids(card: *Card) !RawResources {
+ var result = std.mem.zeroes(RawResources);
+ try Drm.get_resources.request(card.file.handle, RawResources, &result);
+ return result;
+ }
- // NOTE: This function does not take in account
- // that there might be some hot-plugging going
- // on. This might have to change in the future.
- pub fn init(card: *Card) !Self {
- var raw = try Self.raw_without_ids(card);
- const resources = .{
- .fb_ids = try card.allocator.alloc(u32, raw.count_fbs),
- .crtc_ids = try card.allocator.alloc(u32, raw.count_crtcs),
- .connector_ids = try card.allocator.alloc(u32, raw.count_connectors),
- .encoder_ids = try card.allocator.alloc(u32, raw.count_encoders),
- .width = .{ .min = raw.min_width, .max = raw.max_width },
- .height = .{ .min = raw.min_height, .max = raw.max_height },
- .card = card,
- };
+ // NOTE: This function does not take in account
+ // that there might be some hot-plugging going
+ // on. This might have to change in the future.
+ pub fn init(card: *Card) !Self {
+ var raw = try Self.raw_without_ids(card);
+ const resources = .{
+ .fb_ids = try card.allocator.alloc(u32, raw.count_fbs),
+ .crtc_ids = try card.allocator.alloc(u32, raw.count_crtcs),
+ .connector_ids = try card.allocator.alloc(u32, raw.count_connectors),
+ .encoder_ids = try card.allocator.alloc(u32, raw.count_encoders),
+ .width = .{ .min = raw.min_width, .max = raw.max_width },
+ .height = .{ .min = raw.min_height, .max = raw.max_height },
+ .card = card,
+ };
- @memset(resources.fb_ids, 0);
- @memset(resources.crtc_ids, 0);
- @memset(resources.connector_ids, 0);
- @memset(resources.encoder_ids, 0);
+ @memset(resources.fb_ids, 0);
+ @memset(resources.crtc_ids, 0);
+ @memset(resources.connector_ids, 0);
+ @memset(resources.encoder_ids, 0);
- raw.fb_ids = @ptrCast(resources.fb_ids);
- raw.crtc_ids = @ptrCast(resources.crtc_ids);
- raw.connector_ids = @ptrCast(resources.connector_ids);
- raw.encoder_ids = @ptrCast(resources.encoder_ids);
- try Drm.get_resources.request(card.file.handle, RawResources, &raw);
+ raw.fb_ids = @ptrCast(resources.fb_ids);
+ raw.crtc_ids = @ptrCast(resources.crtc_ids);
+ raw.connector_ids = @ptrCast(resources.connector_ids);
+ raw.encoder_ids = @ptrCast(resources.encoder_ids);
+ try Drm.get_resources.request(card.file.handle, RawResources, &raw);
- return resources;
- }
+ return resources;
+ }
- pub fn deinit(self: *Self) void {
- self.card.allocator.free(self.fb_ids);
- self.card.allocator.free(self.crtc_ids);
- self.card.allocator.free(self.connector_ids);
- self.card.allocator.free(self.encoder_ids);
- }
+ pub fn deinit(self: *Self) void {
+ self.card.allocator.free(self.fb_ids);
+ self.card.allocator.free(self.crtc_ids);
+ self.card.allocator.free(self.connector_ids);
+ self.card.allocator.free(self.encoder_ids);
+ }
};
diff --git a/src/screen/main.zig b/src/screen/main.zig
index f11f628..03ef75a 100644
--- a/src/screen/main.zig
+++ b/src/screen/main.zig
@@ -3,118 +3,107 @@ const drm = @import("drm/card.zig");
const Event = @import("drm/event.zig").Event;
pub fn main() !void {
- var gpa = std.heap.GeneralPurposeAllocator(.{}){};
- const allocator = gpa.allocator();
+ var gpa = std.heap.GeneralPurposeAllocator(.{}){};
+ const allocator = gpa.allocator();
- var card = try drm.Card.open("card0", allocator);
- defer card.close();
+ var card = try drm.Card.open("card1", allocator);
+ defer card.close();
- var resources = try card.resources();
- defer resources.deinit();
+ var resources = try card.resources();
+ defer resources.deinit();
- var connector = try card.connector(resources.connector_ids[0]);
- defer connector.deinit();
+ var connector = try card.connector(resources.connector_ids[1]);
+ defer connector.deinit();
- std.debug.print("connector = {}\n", .{ connector.id });
+ std.debug.print("connector = {}\n", .{ connector.id });
- const mode = connector.modes[0];
+ const mode = connector.modes[0];
- std.debug.print("mode = {s}@{d}Hz\n", .{ mode.name, mode.frame_rate() });
+ std.debug.print("mode = {s}@{d}Hz\n", .{ mode.name, mode.frame_rate() });
- var crtc = try crtc: {
- for (connector.encoder_ids) |encoder_id| {
- var encoder = try card.encoder(encoder_id);
- defer encoder.deinit();
+ var crtc = try card.crtc(resources.crtc_ids[
+ connector.compatible_crtc() orelse @panic("no crtc found")
+ ]);
+ defer crtc.detach();
- for (resources.crtc_ids, 0..) |crtc_id, index| {
- if ((encoder.possible_crtcs & (@as(u32, 1) << @intCast(index))) != 0) {
- break :crtc card.crtc(crtc_id);
- }
- }
- }
+ std.debug.print("crtc = {}\n", .{ crtc.id });
- break :crtc error.CrtcNotFound;
- };
- defer crtc.detach();
+ var double_buffer = try card.create_double_buffer(mode.horizontal.size, mode.vertical.size, 32);
+ defer double_buffer.deinit();
- std.debug.print("crtc = {}\n", .{ crtc.id });
+ std.debug.print("buffer = {}, {}x{}, stride = {}\n", .{
+ double_buffer.buffer().id,
+ double_buffer.buffer().width,
+ double_buffer.buffer().height,
+ double_buffer.buffer().stride,
+ });
- var double_buffer = try card.create_double_buffer(mode.horizontal.size, mode.vertical.size, 32);
- defer double_buffer.deinit();
+ try crtc.attach(double_buffer.crtc_buffer(), &connector, mode);
- std.debug.print("buffer = {}, {}x{}, stride = {}\n", .{
- double_buffer.buffer().id,
- double_buffer.buffer().width,
- double_buffer.buffer().height,
- double_buffer.buffer().stride,
- });
+ const Pos = struct { x: f32, y: f32 };
- try crtc.attach(double_buffer.crtc_buffer(), &connector, mode);
+ var vec = Pos { .x = 10, .y = 10 };
+ var pos = Pos { .x = 0, .y = 0 };
+ var delta: f32 = 0;
+ const size = 100;
- const Pos = struct { x: f32, y: f32 };
+ const width: f32 = @floatFromInt(double_buffer.buffer().width);
+ const height: f32 = @floatFromInt(double_buffer.buffer().height);
- var vec = Pos { .x = 10, .y = 10 };
- var pos = Pos { .x = 0, .y = 0 };
- var delta: f32 = 0;
- const size = 100;
+ while (true) {
+ const start = try std.time.Instant.now();
- const width: f32 = @floatFromInt(double_buffer.buffer().width);
- const height: f32 = @floatFromInt(double_buffer.buffer().height);
+ double_buffer.buffer().fill(.{ .red = 0x25, .green = 0x25, .blue = 0x25 });
- while (true) {
- const start = try std.time.Instant.now();
+ pos.x += vec.x * delta;
+ pos.y += vec.y * delta;
- double_buffer.buffer().fill(.{ .red = 0, .green = 0, .blue = 0 });
+ if (pos.x < 0) {
+ pos.x = -pos.x;
+ vec.x = -vec.x;
+ } else if (pos.x + size >= width) {
+ pos.x = width - size;
+ vec.x = -vec.x;
+ }
- pos.x += vec.x * delta;
- pos.y += vec.y * delta;
+ if (pos.y < 0) {
+ pos.y = -pos.y;
+ vec.y = -vec.y;
+ } else if (pos.y + size >= height) {
+ pos.y = height - size;
+ vec.y = -vec.y;
+ }
- if (pos.x < 0) {
- pos.x = -pos.x;
- vec.x = -vec.x;
- } else if (pos.x + size >= width) {
- pos.x = width - size;
- vec.x = -vec.x;
- }
+ for (0..size) |w| {
+ for (0..size) |h| {
+ double_buffer.buffer().set(
+ @as(u32, @intFromFloat(pos.x)) + @as(u32, @intCast(w)),
+ @as(u32, @intFromFloat(pos.y)) + @as(u32, @intCast(h)),
+ .{
+ .red = 0xff,
+ .green = 0,
+ .blue = 0,
+ });
+ }
+ }
- if (pos.y < 0) {
- pos.y = -pos.y;
- vec.y = -vec.y;
- } else if (pos.y + size >= height) {
- pos.y = height - size;
- vec.y = -vec.y;
- }
+ const end = try std.time.Instant.now();
+ const elapsed = (@as(f32, @floatFromInt(end.since(start))) / std.time.ns_per_s);
+ std.debug.print("FPS: {d:.2}\r", .{ 1 / elapsed });
+ delta = elapsed * 60;
- for (0..size) |w| {
- for (0..size) |h| {
- double_buffer.buffer().set(
- @as(u32, @intFromFloat(pos.x)) + @as(u32, @intCast(w)),
- @as(u32, @intFromFloat(pos.y)) + @as(u32, @intCast(h)),
- .{
- .red = 0xff,
- .green = 0,
- .blue = 0,
- });
- }
- }
+ try crtc.page_flip(&double_buffer);
- const end = try std.time.Instant.now();
- const elapsed = (@as(f32, @floatFromInt(end.since(start))) / std.time.ns_per_s);
- std.debug.print("FPS: {d:.2}\r", .{ 1 / elapsed });
- delta = elapsed * 60;
+ while (true) {
+ var event: ?Event = null;
+ while (event == null) {
+ event = try card.poll_event(5000);
+ }
- try crtc.page_flip(&double_buffer);
-
- while (true) {
- var event: ?Event = null;
- while (event == null) {
- event = try card.poll_event(5000);
- }
-
- switch ((event orelse unreachable).type) {
- .page_flip_complete => break,
- else => {},
- }
- }
- }
+ switch ((event orelse unreachable).type) {
+ .page_flip_complete => break,
+ else => {},
+ }
+ }
+ }
}