7#include <lib/zx/vmar.h>
14#include "flutter/fml/logging.h"
18constexpr uint64_t kBytesPerPixel = 4;
26 FML_CHECK(rotation == 0 || rotation == 90 || rotation == 270);
27 if (rotation == 90 || rotation == 270) {
32 screenshot_vmo.get_prop_content_size(&vmo_size);
33 FML_CHECK(vmo_size == kBytesPerPixel * width_ * height_);
34 uint8_t* vmo_host =
nullptr;
35 auto status = zx::vmar::root_self()->map(
36 ZX_VM_PERM_READ, 0, screenshot_vmo,
37 0, vmo_size,
reinterpret_cast<uintptr_t*
>(&vmo_host));
39 ExtractScreenshotFromVMO(vmo_host);
41 uintptr_t address =
reinterpret_cast<uintptr_t
>(vmo_host);
42 status = zx::vmar::root_self()->unmap(address, vmo_size);
47 return stream <<
"{Pixel:" <<
" r:" <<
static_cast<unsigned int>(pixel.
red)
48 <<
" g:" <<
static_cast<unsigned int>(pixel.
green)
49 <<
" b:" <<
static_cast<unsigned int>(pixel.
blue)
50 <<
" a:" <<
static_cast<unsigned int>(pixel.
alpha) <<
"}";
54 FML_CHECK(
x >= 0 && x < width_ && y >= 0 &&
y < height_)
55 <<
"Index out of bounds";
56 return screenshot_[
y][
x];
60 std::map<Pixel, uint32_t> histogram;
61 FML_CHECK(screenshot_.size() == height_ && screenshot_[0].size() == width_);
62 for (
size_t i = 0;
i < height_;
i++) {
63 for (
size_t j = 0; j < width_; j++) {
64 histogram[screenshot_[
i][j]]++;
70void Screenshot::ExtractScreenshotFromVMO(uint8_t* screenshot_vmo) {
72 for (
size_t i = 0;
i < height_;
i++) {
75 screenshot_.push_back(GetPixelsInRow(screenshot_vmo,
i));
79std::vector<Pixel> Screenshot::GetPixelsInRow(uint8_t* screenshot_vmo,
81 std::vector<Pixel> row;
82 for (
size_t col_idx = 0;
83 col_idx < static_cast<size_t>(width_ * kBytesPerPixel);
84 col_idx += kBytesPerPixel) {
88 auto pixel_start_index = row_index * width_ * kBytesPerPixel;
96 row.emplace_back(screenshot_vmo[pixel_start_index + col_idx],
97 screenshot_vmo[pixel_start_index + col_idx + 1],
98 screenshot_vmo[pixel_start_index + col_idx + 2],
99 screenshot_vmo[pixel_start_index + col_idx + 3]);
void swap(sk_sp< T > &a, sk_sp< T > &b)
Screenshot(const zx::vmo &screenshot_vmo, uint64_t width, uint64_t height, int rotation)
Pixel GetPixelAt(uint64_t x, uint64_t y) const
std::map< Pixel, uint32_t > Histogram() const
#define FML_CHECK(condition)
std::ostream & operator<<(std::ostream &stream, const Pixel &pixel)