vladimir
vladimir

Reputation: 1

Which method is responsible for taking screenshots in Darwin OS?

I'm trying to find a class in the Darwin OS source code in which the functionality of taking screenshots.

I found out that video_console.c is responsible for displaying the image on the screen, but I couldn't get any further. Does anyone know where this code is located? Thank u.

Upvotes: 0

Views: 61

Answers (1)

pmdj
pmdj

Reputation: 23438

As hinted by another commenter, this is not something you'd do from the kernel (xnu) but rather the windowing system. Modern OSes lean heavily on the GPU's hardware accelerated features, so there typically isn't a single framebuffer holding the display content, and even if there is, it's not centrally accessible.

You have tagged both macOS and iOS in the question; the answer differs.

On macOS, you can use CGDisplayCreateImage or variants. Note that your app needs to get the user's consent for this API to work.

On iOS, it's a little more complicated. Within your app, you can draw your view hierarchy to an off screen context. This isn't a direct screenshot, but by far the easiest solution if you just need to save what your app is currently showing. Beyond that, the only solution I'm aware of is ReplayKit. This provides a video stream rather than a single image, so you'll need to deal with that.

Upvotes: 1

Related Questions