Skip to content

Commit 9018c44

Browse files
committed
Add screenshot driver callback definition.
1 parent 7759cbc commit 9018c44

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

lib/scenic/driver.ex

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,51 @@ defmodule Scenic.Driver do
311311
driver :: Driver.t()
312312
) :: {:ok, Driver.t()}
313313

314+
@typedoc """
315+
An encoding for the bytes in a screenshot.
316+
317+
* `:rgba` is 32-bit `:rgba`
318+
* `:rgb` is 24-bit `:rgb`
319+
"""
320+
@type screenshot_encoding_t :: :rgba | :rgb
321+
322+
@typedoc """
323+
A screenshot, a tuple consisting of
324+
325+
`{width, height, encoding, <bytes>}`
326+
327+
where
328+
329+
* `width` is a positive (>0) integer
330+
* `height` is a positive (>0) integer
331+
* `encoding` is a `screenshot_encoding_t`
332+
* `bytes` is a bitstring frame buffer of size `width * height * <size of encoding>`
333+
334+
`size_of_encoding` can be 3 (for `rgb`) or 4 (for `rgba`).
335+
"""
336+
@type screenshot_t :: {
337+
pos_integer(),
338+
pos_integer(),
339+
screenshot_encoding_t,
340+
bitstring()
341+
}
342+
343+
@doc """
344+
Called to get a screenshot of the current backbuffer.
345+
346+
This is a synchronous call in order to support remote/web drivers.
347+
348+
This callback is optional.
349+
"""
350+
@callback take_screenshot(driver :: Driver.t()) ::
351+
{:ok, :not_supported} | {:ok, screenshot_t, Driver.t()}
352+
314353
@optional_callbacks reset_scene: 1,
315354
request_input: 2,
316355
update_scene: 2,
317356
del_scripts: 2,
318-
clear_color: 2
357+
clear_color: 2,
358+
take_screenshot: 1
319359

320360
# ===========================================================================
321361
defmodule Error do

0 commit comments

Comments
 (0)