class Screenshot

Defined at line 24 of file ../../src/ui/testing/util/screenshot_helper.h

Helper class to get information about a screenshot returned by

|fuchsia.ui.composition.Screenshot| protocol.

Public Methods

void Screenshot (const zx::vmo & screenshot_vmo, uint64_t width, uint64_t height, int rotation, fuchsia::ui::composition::ScreenshotFormat format)

Params:-

|screenshot_vmo| - The VMO returned by |fuchsia.ui.composition.Screenshot.Take| representing

the screenshot data in BGRA.

|width|, |height| - Width and height of the physical display in pixels as

returned by |fuchsia.ui.display.singleton.Info|.

|rotation| - The display rotation value in degrees. The width and the height of the screenshot

are flipped if this value is 90 or 270 degrees as the screenshot shows how content

is seen by the user.

|format| - The raw pixel format to be used for this screenshot. Defaults to BGRA.

Defined at line 39 of file ../../src/ui/testing/util/screenshot_helper.cc

void Screenshot (const zx::vmo & png_vmo)

Use this specifically to create a |Screenshot| object from a PNG encoded vmo.

Defined at line 70 of file ../../src/ui/testing/util/screenshot_helper.cc

void Screenshot ()

An empty screenshot.

Defined at line 68 of file ../../src/ui/testing/util/screenshot_helper.cc

std::vector<std::vector<Pixel>> screenshot ()

Returns a 2D vector of size |height_ * width_|. Each value in the vector corresponds to a pixel

in the screenshot.

Defined at line 78 of file ../../src/ui/testing/util/screenshot_helper.h

uint64_t width ()

Defined at line 80 of file ../../src/ui/testing/util/screenshot_helper.h

Pixel GetPixelAt (uint64_t x, uint64_t y)

Returns the |Pixel| located at (x,y) coordinates. |x| and |y| should range from [0,width_) and

[0,height_) respectively.

(0,0)________________width_____________(w-1,0)

| | |

| | y |h

| x | |e

|-----------------------X |i

| |g

| |h

| |t

|_________________________________|

(0,h-1) screenshot (w-1,h-1)

Clients should only use this function to get the pixel data.

Defined at line 80 of file ../../src/ui/testing/util/screenshot_helper.cc

uint64_t height ()

Defined at line 82 of file ../../src/ui/testing/util/screenshot_helper.h

size_t size ()

Defined at line 84 of file ../../src/ui/testing/util/screenshot_helper.h

std::map<Pixel, uint32_t> Histogram ()

Counts the frequencies of each color in a screenshot.

Defined at line 85 of file ../../src/ui/testing/util/screenshot_helper.cc

float ComputeSimilarity (const Screenshot & other)

Returns percentage of pixels that match by comparing two screenshots. Returns 0 if the sizes of

the screenshots do not match.

Defined at line 98 of file ../../src/ui/testing/util/screenshot_helper.cc

float ComputeHistogramSimilarity (const Screenshot & other)

Returns percentage of pixels that match by comparing the histograms of two screenshots,

allowing for pixel movement (e.g. shift, rotation) in the image. The comparison is

performed by measuring the percentage of the area of the histograms that overlaps,

i.e. the number of pixels that are both histograms.

Returns 0 if the sizes of the screenshots do not match.

Defined at line 112 of file ../../src/ui/testing/util/screenshot_helper.cc

bool LoadFromPng (const std::string & png_filename)

Loads the screenshot from a PNG file.

Defined at line 199 of file ../../src/ui/testing/util/screenshot_helper.cc

bool DumpToCustomArtifacts (const std::string & filename)

Dumps the screenshot as a BGRA raw file to /custom_artifacts. Returns true if it is successful.

Note that the custom_artifacts storage capability needs to be added to the test. See

https://fuchsia.dev/fuchsia-src/development/testing/components/test_runner_framework?hl=en#custom-artifacts

for more details.

Defined at line 129 of file ../../src/ui/testing/util/screenshot_helper.cc

bool DumpPngToCustomArtifacts (const std::string & filename)

Dumps the screenshot as a PNG file to /custom_artifacts. Returns true if it is successful.

Note that the custom_artifacts storage capability needs to be added to the test. See

https://fuchsia.dev/fuchsia-src/development/testing/components/test_runner_framework?hl=en#custom-artifacts

for more details.

Defined at line 148 of file ../../src/ui/testing/util/screenshot_helper.cc

std::vector<std::pair<uint32_t, utils::Pixel>> LogHistogramTopPixels (int num_top_pixels)

Returns the top pixels in the histogram and prints logs.

Defined at line 254 of file ../../src/ui/testing/util/screenshot_helper.cc

void ExtractScreenshotFromPngVMO (zx::vmo & png_vmo)

Decode PNG-encoded VMO back to raw format and populate screenshot_ with raw pixels.

Done this way for testing purposes so we can compare accuracy of screenshots taken in PNG format.

Defined at line 318 of file ../../src/ui/testing/util/screenshot_helper.cc