There is no OS feature for capturing the external display.
The main display is composited from a number of sources, as is the external display. The "screen capture" feature is actually just another way to composite the various sources. Because it uses the same parameters as the main display, you get the same output. (Note that any "secure" layers, such as DRM-protected video, do not appear however.) So to "capture" the external display, you'd want a screen capture variant that uses the external display "layer stack" rather than the main, and there is no API for doing so.
(See SurfaceFlinger::captureScreenImplLocked()
in SurfaceFlinger.cpp.)
The screenrecord
command does something similar: it creates a virtual display with the main display's layer stack, and captures whatever gets rendered there.
As far as capturing the output of a Presentation
goes, there are a couple of CTS tests that may be of interest. The VirtualDisplayTest creates a Presentation
and captures it with an ImageReader, while EncodeVirtualDisplayTest feeds the Presentation through a full video encode/decode path. The tests just draw a series of colors and then check to make sure the colors can be read back. Both of these require recent very versions of Android (e.g. ImageReader
didn't exist until API 19), and the app's limited permissions will restrict the output to what the app itself is rendering.