Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::CompressedImageSkia Class Referencefinal

#include <compressed_image_skia.h>

Inheritance diagram for impeller::CompressedImageSkia:
impeller::CompressedImage

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< CompressedImageCreate (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::Mappingsource_
 

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 35 of file compressed_image_skia.cc.

37 : CompressedImage(std::move(allocation)) {}
CompressedImage(std::shared_ptr< const fml::Mapping > 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 26 of file compressed_image_skia.cc.

27 {
28 // There is only one backend today.
29 if (!allocation) {
30 return nullptr;
31 }
32 return std::make_shared<CompressedImageSkia>(std::move(allocation));
33}

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

◆ Decode()

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

Implements impeller::CompressedImage.

Definition at line 42 of file compressed_image_skia.cc.

42 {
43 if (!IsValid()) {
44 return {};
45 }
46 if (source_->GetSize() == 0u) {
47 return {};
48 }
49
50 auto src = new std::shared_ptr<const fml::Mapping>(source_);
51 auto sk_data = SkData::MakeWithProc(
52 source_->GetMapping(), source_->GetSize(),
53 [](const void* ptr, void* context) {
54 delete reinterpret_cast<decltype(src)>(context);
55 },
56 src);
57
58 std::unique_ptr<SkCodec> codec;
59 if (SkBmpDecoder::IsBmp(sk_data->bytes(), sk_data->size())) {
60 codec = SkBmpDecoder::Decode(sk_data, nullptr);
61 } else if (SkGifDecoder::IsGif(sk_data->bytes(), sk_data->size())) {
62 codec = SkGifDecoder::Decode(sk_data, nullptr);
63 } else if (SkIcoDecoder::IsIco(sk_data->bytes(), sk_data->size())) {
64 codec = SkIcoDecoder::Decode(sk_data, nullptr);
65 } else if (SkJpegDecoder::IsJpeg(sk_data->bytes(), sk_data->size())) {
66 codec = SkJpegDecoder::Decode(sk_data, nullptr);
67 } else if (SkPngDecoder::IsPng(sk_data->bytes(), sk_data->size())) {
68 codec = SkPngDecoder::Decode(sk_data, nullptr);
69 } else if (SkWebpDecoder::IsWebp(sk_data->bytes(), sk_data->size())) {
70 codec = SkWebpDecoder::Decode(sk_data, nullptr);
71 } else if (SkWbmpDecoder::IsWbmp(sk_data->bytes(), sk_data->size())) {
72 codec = SkWbmpDecoder::Decode(sk_data, nullptr);
73 }
74 if (!codec) {
75 VALIDATION_LOG << "Image data was not valid.";
76 return {};
77 }
78
79 const auto dims = codec->dimensions();
80 auto info = SkImageInfo::Make(dims.width(), dims.height(),
81 kRGBA_8888_SkColorType, kPremul_SkAlphaType);
82
83 auto bitmap = std::make_shared<SkBitmap>();
84 if (!bitmap->tryAllocPixels(info)) {
85 VALIDATION_LOG << "Could not allocate arena for decompressing image.";
86 return {};
87 }
88
89 // We extract this to an SkImage first because not all codecs can directly
90 // swizzle via getPixels.
91 auto image = SkCodecs::DeferredImage(std::move(codec));
92 if (!image) {
93 VALIDATION_LOG << "Could not extract image from compressed data.";
94 return {};
95 }
96
97 if (!image->readPixels(nullptr, bitmap->pixmap(), 0, 0)) {
98 VALIDATION_LOG << "Could not resize image into arena.";
99 return {};
100 }
101
102 auto mapping = std::make_shared<fml::NonOwnedMapping>(
103 reinterpret_cast<const uint8_t*>(bitmap->pixmap().addr()), // data
104 bitmap->pixmap().rowBytes() * bitmap->pixmap().height(), // size
105 [bitmap](const uint8_t* data, size_t size) mutable {
106 bitmap.reset();
107 } // proc
108 );
109
110 return {
111 {bitmap->pixmap().dimensions().fWidth,
112 bitmap->pixmap().dimensions().fHeight}, // size
114 mapping // allocation
115 };
116}
const std::shared_ptr< const fml::Mapping > source_
FlutterVulkanImage * image
std::shared_ptr< SkBitmap > bitmap
std::shared_ptr< const fml::Mapping > data
#define VALIDATION_LOG
Definition validation.h:91

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


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