10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "third_party/skia/include/core/SkData.h"
12 #include "third_party/skia/include/core/SkImage.h"
13 #include "third_party/skia/include/core/SkPixmap.h"
14 #include "third_party/skia/include/core/SkRefCnt.h"
19 std::shared_ptr<const fml::Mapping> allocation) {
24 return std::make_shared<CompressedImageSkia>(std::move(allocation));
28 std::shared_ptr<const fml::Mapping> allocation)
42 auto src =
new std::shared_ptr<const fml::Mapping>(
source_);
43 auto sk_data = SkData::MakeWithProc(
45 [](
const void* ptr,
void* context) {
46 delete reinterpret_cast<decltype(src)>(context);
50 auto image = SkImages::DeferredFromEncodedData(sk_data);
55 const auto dims = image->imageInfo().dimensions();
56 auto info = SkImageInfo::Make(dims.width(), dims.height(),
57 kRGBA_8888_SkColorType, kPremul_SkAlphaType);
59 auto bitmap = std::make_shared<SkBitmap>();
60 if (!bitmap->tryAllocPixels(info)) {
61 VALIDATION_LOG <<
"Could not allocate arena for decompressing image.";
65 if (!image->readPixels(
nullptr, bitmap->pixmap(), 0, 0)) {
70 auto mapping = std::make_shared<fml::NonOwnedMapping>(
71 reinterpret_cast<const uint8_t*
>(bitmap->pixmap().addr()),
72 bitmap->pixmap().rowBytes() * bitmap->pixmap().height(),
73 [bitmap](
const uint8_t*
data,
size_t size)
mutable {
79 {bitmap->pixmap().dimensions().fWidth,
80 bitmap->pixmap().dimensions().fHeight},
const std::shared_ptr< const fml::Mapping > source_
CompressedImageSkia(std::shared_ptr< const fml::Mapping > allocation)
~CompressedImageSkia() override
static std::shared_ptr< CompressedImage > Create(std::shared_ptr< const fml::Mapping > allocation)
DecompressedImage Decode() const override
std::shared_ptr< const fml::Mapping > data