1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
const std = @import("std");
const drm = @import("drm/card.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var card = try drm.Card.open("card0", allocator);
defer card.close();
var resources = try card.resources();
defer resources.deinit();
var connector = try card.connector(resources.connector_ids[0]);
defer connector.deinit();
std.debug.print("connector = {}\n", .{ connector.id });
const mode = connector.modes[0];
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();
for (resources.crtc_ids, 0..) |crtc_id, index| {
if ((encoder.possible_crtcs & (@as(u32, 1) << @intCast(index))) != 0) {
break :crtc card.crtc(crtc_id);
}
}
}
break :crtc error.CrtcNotFound;
};
defer crtc.detach();
std.debug.print("crtc = {}\n", .{ crtc.id });
var framebuffer = try card.create_frame_buffer(mode.horizontal.size, mode.vertical.size, 32);
defer framebuffer.deinit();
std.debug.print("framebuffer = {}, {}\n", .{ framebuffer.id, framebuffer.canvas_size });
try crtc.attach(&framebuffer, &connector, mode);
var frame: u24 = 0;
while (true) {
for (0..framebuffer.width) |x| {
for (0..framebuffer.height) |y| {
const raster_x = (frame + x) / 100 * 100;
const raster_y = y / 100 * 100;
const color = ((raster_x + raster_y) + 0x129453) * 0x329120;
framebuffer.set(@intCast(x), @intCast(y), .{
.red = @intCast(color & 0xff),
.green = @intCast((color >> 8) & 0xff),
.blue = @intCast((color >> 16) & 0xff),
});
}
}
frame, _ = @addWithOverflow(frame, 1);
try crtc.attach(&framebuffer, &connector, mode);
std.time.sleep(@intFromFloat(1000000000 / mode.frame_rate()));
}
while (true) { std.time.sleep(5000000000); }
}
|