| Flutter Impeller |

Public Member Functions | Static Public Member Functions | List of all members
impeller::CompressedImageSkia Class Referencefinal

`#include <compressed_image_skia.h>`

Inheritance diagram for impeller::CompressedImageSkia:

## Public Member Functions
| CompressedImageSkia (std::shared_ptr< const fml::Mapping > allocation)
| ~CompressedImageSkia () override
DecompressedImage | Decode () const override
Public Member Functions inherited from impeller::CompressedImage
virtual | ~CompressedImage ()
bool | IsValid () const

## Static Public Member Functions
static std::shared_ptr< CompressedImage > | Create (std::shared_ptr< const fml::Mapping > allocation)

## Additional Inherited Members
Protected Member Functions inherited from impeller::CompressedImage
| CompressedImage (std::shared_ptr< const fml::Mapping > allocation)
Protected Attributes inherited from impeller::CompressedImage
const std::shared_ptr< const fml::Mapping > | source_

## Detailed Description

Definition at line 12 of file compressed_image_skia.h.

## Constructor & Destructor Documentation

## ◆ CompressedImageSkia()

impeller::CompressedImageSkia::CompressedImageSkia | ( | std::shared_ptr< const fml::Mapping > | allocation | ) |
| explicit

Definition at line 27 of file compressed_image_skia.cc.

29 : CompressedImage(std::move(allocation)) {}

## ◆ ~CompressedImageSkia()

impeller::CompressedImageSkia::~CompressedImageSkia | ( |  | ) |
| overridedefault

## Member Function Documentation

## ◆ Create()

std::shared_ptr< CompressedImage > impeller::CompressedImageSkia::Create | ( | std::shared_ptr< const fml::Mapping > | allocation | ) |
| static

Definition at line 18 of file compressed_image_skia.cc.

19 {
20 // There is only one backend today.
21 if (!allocation) {
22 return nullptr;
23 }
24 return std::make_shared<CompressedImageSkia>(std::move(allocation));
25 }

Referenced by impeller::Playground::LoadFixtureImageCompressed().

## ◆ Decode()

DecompressedImage impeller::CompressedImageSkia::Decode | ( |  | ) | const
| overridevirtual

Implements impeller::CompressedImage.

Definition at line 34 of file compressed_image_skia.cc.

34 {
35 if (!IsValid()) {
36 return {};
37 }
38 if (source_->GetSize() == 0u) {
39 return {};
40 }
41
42 auto src = new std::shared_ptr<const fml::Mapping>(source_);
43 auto sk_data = SkData::MakeWithProc(
44 source_->GetMapping(), source_->GetSize(),
45 [](const void* ptr, void* context) {
46 delete reinterpret_cast<decltype(src)>(context);
47 },
48 src);
49
50 auto image = SkImages::DeferredFromEncodedData(sk_data);
51 if (!image) {
52 return {};
53 }
54
55 const auto dims = image->imageInfo().dimensions();
56 auto info = SkImageInfo::Make(dims.width(), dims.height(),
57 kRGBA_8888_SkColorType, kPremul_SkAlphaType);
58
59 auto bitmap = std::make_shared<SkBitmap>();
60 if (!bitmap->tryAllocPixels(info)) {
61 VALIDATION_LOG << "Could not allocate arena for decompressing image.";
62 return {};
63 }
64
65 if (!image->readPixels(nullptr, bitmap->pixmap(), 0, 0)) {
66 VALIDATION_LOG << "Could not decompress image into arena.";
67 return {};
68 }
69
70 auto mapping = std::make_shared<fml::NonOwnedMapping>(
71 reinterpret_cast<const uint8_t*>(bitmap->pixmap().addr()), // data
72 bitmap->pixmap().rowBytes() * bitmap->pixmap().height(), // size
73 [bitmap](const uint8_t* data, size_t size) mutable {
74 bitmap.reset();
75 } // proc
76 );
77
78 return {
79 {bitmap->pixmap().dimensions().fWidth,
80 bitmap->pixmap().dimensions().fHeight}, // size
81 DecompressedImage::Format::kRGBA, // format
82 mapping // allocation
83 };
84 }

References data, impeller::CompressedImage::IsValid(), impeller::DecompressedImage::kRGBA, impeller::CompressedImage::source_, and VALIDATION_LOG.

The documentation for this class was generated from the following files:

- impeller/playground/image/backends/skia/compressed_image_skia.h
- impeller/playground/image/backends/skia/compressed_image_skia.cc

impeller::CompressedImage::source_
const std::shared_ptr< const fml::Mapping > source_
Definition: compressed_image.h:26
impeller::DecompressedImage::Format::kRGBA
@ kRGBA
impeller::CompressedImage::CompressedImage
CompressedImage(std::shared_ptr< const fml::Mapping > allocation)
Definition: compressed_image.cc:9
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::CompressedImage::IsValid
bool IsValid() const
Definition: compressed_image.cc:14