Hi.
I'm currently investigating on how to capture the content of the current screen in my software using multiple DRM planes. I figured during the atomic commit I already implement for showing the content on the screen, I additionally, upon requesting a screenshot, I do the following:
I'm on a full updated Raspberry Pi OS:
Linux raspberrypi 6.1.0-rpi7-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.63-1+rpt1 (2023-11-24) aarch64 GNU/Linux
pi@raspberrypi:~ $ vcgencmd version
2024/01/05 15:57:40
Copyright (c) 2012 Broadcom
version 30cc5f37 (release) (embedded)
dmesg output:
I'm currently investigating on how to capture the content of the current screen in my software using multiple DRM planes. I figured during the atomic commit I already implement for showing the content on the screen, I additionally, upon requesting a screenshot, I do the following:
- Ensure the writeback's connector CRTC_ID value is set to its default assigned, normally unused, CRTC (57 in my case)
- Set to the wb connector's WRITEBACK_OUT_FENCE_PTR to a pointer to a uint64_t file descriptor
- Set the CRTC's ACTIVE to 1 and MODE_ID to the same mode that the HDMI CRTC uses
- Allocate a new dumb buffer with the matching size and 24 bit depth.
- Use the dumb buffer's handle to drmModeAddFB2 a new frame buffer with format DRM_FORMAT_RGB888
- Set the wb connector's WRITEBACK_FB_ID to the newly created frame buffer.
- Assign the already to-be-shown-on-screen frame buffers additionally to unused planes matching the writeback CRTC.
- Do a successful atomic commit.
- At that point, from what I understand, the content is both rendered on screen, as well as into the RGB888 frame buffer allocated before?
- I poll() on the now filled FENCE fd and it returns as readable.
- I use the dumb buffer's handle to get a mmap offset using drmModeMapDumbBuffer
- I mmap the drm_fd at that location using pixels = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, drm.fd, mmap_offset)
- That all still works without obvious error message, but the data pointed to by 'pixels' is all zeros.
I'm on a full updated Raspberry Pi OS:
Linux raspberrypi 6.1.0-rpi7-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.63-1+rpt1 (2023-11-24) aarch64 GNU/Linux
pi@raspberrypi:~ $ vcgencmd version
2024/01/05 15:57:40
Copyright (c) 2012 Broadcom
version 30cc5f37 (release) (embedded)
dmesg output:
Code:
[ 7529.420985] vc4-drm axi:gpu: [drm:drm_atomic_state_init [drm]] Allocated atomic state 000000003066aa3a[ 7529.421034] vc4-drm axi:gpu: [drm:drm_atomic_get_plane_state [drm]] Added [PLANE:47:plane-0] 00000000006b9f7b state to 000000003066aa3a[ 7529.421097] vc4-drm axi:gpu: [drm:drm_atomic_set_fb_for_plane [drm]] Set [FB:306] for [PLANE:47:plane-0] state 00000000006b9f7b[ 7529.421142] [drm:drm_mode_object_get [drm]] OBJ ID: 306 (3)[ 7529.421178] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 306 (4)[ 7529.421214] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 306 (3)[ 7529.421251] vc4-drm axi:gpu: [drm:drm_atomic_get_crtc_state [drm]] Added [CRTC:57:mop] 0000000091086c64 state to 000000003066aa3a[ 7529.421287] vc4-drm axi:gpu: [drm:drm_atomic_set_crtc_for_plane [drm]] Link [PLANE:47:plane-0] state 00000000006b9f7b to [CRTC:57:mop][ 7529.421326] [drm:drm_mode_object_get [drm]] OBJ ID: 304 (4)[ 7529.421361] vc4-drm axi:gpu: [drm:drm_atomic_set_mode_prop_for_crtc [drm]] Set [MODE:1920x1080 @ 60Hz 16:9] for [CRTC:57:mop] state 0000000091086c64[ 7529.421397] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 304 (5)[ 7529.421432] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 304 (4)[ 7529.421469] [drm:drm_mode_object_get [drm]] OBJ ID: 63 (2)[ 7529.421504] vc4-drm axi:gpu: [drm:drm_atomic_get_connector_state [drm]] Added [CONNECTOR:63:Writeback-1] 00000000caf67ce5 state to 000000003066aa3a[ 7529.421540] [drm:drm_mode_object_get [drm]] OBJ ID: 63 (3)[ 7529.421575] vc4-drm axi:gpu: [drm:drm_atomic_set_crtc_for_connector [drm]] Link [CONNECTOR:63:Writeback-1] state 00000000caf67ce5 to [CRTC:57:mop][ 7529.421612] [drm:drm_mode_object_get [drm]] OBJ ID: 307 (3)[ 7529.421648] vc4-drm axi:gpu: [drm:drm_atomic_set_property [drm]] Set [FB:307] for connector state 00000000caf67ce5[ 7529.421683] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 307 (4)[ 7529.421718] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 307 (3)[ 7529.421754] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 63 (4)[ 7529.421790] [drm:drm_mode_object_get [drm]] OBJ ID: 300 (2)[ 7529.421826] vc4-drm axi:gpu: [drm:drm_atomic_get_plane_state [drm]] Added [PLANE:100:plane-4] 0000000076b8796b state to 000000003066aa3a[ 7529.421862] [drm:drm_mode_object_get [drm]] OBJ ID: 304 (3)[ 7529.421897] vc4-drm axi:gpu: [drm:drm_atomic_get_crtc_state [drm]] Added [CRTC:88:crtc-2] 00000000314c8dc4 state to 000000003066aa3a[ 7529.421933] vc4-drm axi:gpu: [drm:drm_atomic_set_fb_for_plane [drm]] Set [FB:306] for [PLANE:100:plane-4] state 0000000076b8796b[ 7529.421969] [drm:drm_mode_object_get [drm]] OBJ ID: 306 (4)[ 7529.422004] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 300 (3)[ 7529.422039] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 306 (5)[ 7529.422074] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 306 (4)[ 7529.422113] vc4-drm axi:gpu: [drm:drm_atomic_check_only [drm]] checking 000000003066aa3a[ 7529.422152] vc4-drm axi:gpu: [drm:drm_atomic_get_private_obj_state [drm]] Added new private object 00000000fe04ca90 state 0000000031a77798 to 000000003066aa3a[ 7529.422188] vc4-drm axi:gpu: [drm:vc4_atomic_check [vc4]] crtc-2: Trying to find a channel.[ 7529.422206] vc4-drm axi:gpu: [drm:vc4_atomic_check [vc4]] crtc-2: Already enabled, reusing channel 0.[ 7529.422220] vc4-drm axi:gpu: [drm:vc4_atomic_check [vc4]] mop: Trying to find a channel.[ 7529.422235] vc4-drm axi:gpu: [drm:vc4_atomic_check [vc4]] Assigned HVS channel 2 to CRTC mop[ 7529.422250] vc4-drm axi:gpu: [drm:drm_atomic_helper_check_modeset [drm_kms_helper]] [CRTC:57:mop] mode changed[ 7529.422272] vc4-drm axi:gpu: [drm:drm_atomic_helper_check_modeset [drm_kms_helper]] [CRTC:57:mop] enable changed[ 7529.422291] vc4-drm axi:gpu: [drm:drm_atomic_helper_check_modeset [drm_kms_helper]] [CRTC:57:mop] active changed[ 7529.422314] vc4-drm axi:gpu: [drm:drm_atomic_helper_check_modeset [drm_kms_helper]] Updating routing for [CONNECTOR:63:Writeback-1][ 7529.422334] vc4-drm axi:gpu: [drm:drm_atomic_helper_check_modeset [drm_kms_helper]] [CONNECTOR:63:Writeback-1] using [ENCODER:58:Virtual-58] on [CRTC:57:mop][ 7529.422353] vc4-drm axi:gpu: [drm:drm_atomic_helper_check_modeset [drm_kms_helper]] [CRTC:57:mop] needs all connectors, enable: y, active: y[ 7529.422372] vc4-drm axi:gpu: [drm:drm_atomic_add_affected_connectors [drm]] Adding all current connectors for [CRTC:57:mop] to 000000003066aa3a[ 7529.422411] vc4-drm axi:gpu: [drm:drm_atomic_add_affected_planes [drm]] Adding all current planes for [CRTC:57:mop] to 000000003066aa3a[ 7529.422449] vc4-drm axi:gpu: [drm:drm_atomic_add_encoder_bridges [drm]] Adding all bridges for [encoder:58:Virtual-58] to 000000003066aa3a[ 7529.422486] [drm:drm_atomic_normalize_zpos [drm]] [CRTC:57:mop] calculating normalized zpos values[ 7529.422522] [drm:drm_atomic_normalize_zpos [drm]] [PLANE:47:plane-0] processing zpos value 0[ 7529.422558] [drm:drm_atomic_normalize_zpos [drm]] [PLANE:47:plane-0] normalized zpos value 0[ 7529.422597] vc4-drm axi:gpu: [drm:vc4_plane_atomic_check [vc4]] [PLANE:47:plane-0] Computed DLIST size: 18[ 7529.422613] vc4-drm axi:gpu: [drm:vc4_plane_atomic_check [vc4]] [PLANE:47:plane-0] LBM Allocation Size: 80[ 7529.422630] vc4-drm axi:gpu: [drm:vc4_plane_atomic_check [vc4]] [PLANE:100:plane-4] Computed DLIST size: 18[ 7529.422644] vc4-drm axi:gpu: [drm:vc4_plane_atomic_check [vc4]] [PLANE:100:plane-4] LBM Allocation Size: 80[ 7529.422659] vc4-drm axi:gpu: [drm:vc4_hvs_atomic_check [vc4]] [CRTC:57:mop] Found [PLANE:47:plane-0] with DLIST size: 18[ 7529.422674] vc4-drm axi:gpu: [drm:vc4_hvs_atomic_check [vc4]] [CRTC:57:mop] Allocating DLIST block with size: 19[ 7529.422690] vc4-drm axi:gpu: [drm:vc4_hvs_atomic_check [vc4]] [CRTC:88:crtc-2] Found [PLANE:100:plane-4] with DLIST size: 18[ 7529.422705] vc4-drm axi:gpu: [drm:vc4_hvs_atomic_check [vc4]] [CRTC:88:crtc-2] Allocating DLIST block with size: 19[ 7529.422722] vc4-drm axi:gpu: [drm:drm_atomic_get_private_obj_state [drm]] Added new private object 00000000beac710f state 000000009c8d8af2 to 000000003066aa3a[ 7529.422761] vc4-drm axi:gpu: [drm:drm_atomic_commit [drm]] committing 000000003066aa3a[ 7529.422808] vc4-drm axi:gpu: [drm:drm_calc_timestamping_constants [drm]] crtc 57: hwmode: htotal 2200, vtotal 1125, vdisplay 1080[ 7529.422844] vc4-drm axi:gpu: [drm:drm_calc_timestamping_constants [drm]] crtc 57: clock 148500 kHz framedur 16666666 linedur 14814[ 7529.422880] vc4-drm axi:gpu: [drm:drm_calc_timestamping_constants [drm]] crtc 88: hwmode: htotal 2200, vtotal 1125, vdisplay 1080[ 7529.422916] vc4-drm axi:gpu: [drm:drm_calc_timestamping_constants [drm]] crtc 88: clock 148500 kHz framedur 16666666 linedur 14814[ 7529.422952] vc4-drm axi:gpu: [drm:crtc_set_mode [drm_kms_helper]] modeset on [ENCODER:58:Virtual-58][ 7529.422979] vc4-drm axi:gpu: [drm:drm_atomic_helper_commit_modeset_enables [drm_kms_helper]] enabling [CRTC:57:mop][ 7529.422998] vc4-drm axi:gpu: [drm:drm_vblank_enable [drm]] enabling vblank on crtc 0, ret: 0[ 7529.423036] vc4-drm axi:gpu: [drm:drm_atomic_helper_commit_modeset_enables [drm_kms_helper]] enabling [ENCODER:58:Virtual-58][ 7529.431148] [drm:drm_mode_object_put.part.0 [drm]] OBJ ID: 307 (2)[ 7529.431202] vc4-drm axi:gpu: [drm:drm_atomic_state_default_clear [drm]] Clearing atomic state 000000003066aa3aStatistics: Posted by dividuum — Wed Jan 17, 2024 2:16 pm