10 #include "third_party/skia/include/codec/SkBmpDecoder.h"
11 #include "third_party/skia/include/codec/SkCodec.h"
12 #include "third_party/skia/include/codec/SkGifDecoder.h"
13 #include "third_party/skia/include/codec/SkIcoDecoder.h"
14 #include "third_party/skia/include/codec/SkJpegDecoder.h"
15 #include "third_party/skia/include/codec/SkPngDecoder.h"
16 #include "third_party/skia/include/codec/SkWbmpDecoder.h"
17 #include "third_party/skia/include/codec/SkWebpDecoder.h"
18 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "third_party/skia/include/core/SkData.h"
20 #include "third_party/skia/include/core/SkImage.h"
21 #include "third_party/skia/include/core/SkPixmap.h"
22 #include "third_party/skia/include/core/SkRefCnt.h"
27 std::shared_ptr<const fml::Mapping> allocation) {
32 return std::make_shared<CompressedImageSkia>(std::move(allocation));
36 std::shared_ptr<const fml::Mapping> allocation)
50 auto src =
new std::shared_ptr<const fml::Mapping>(
source_);
51 auto sk_data = SkData::MakeWithProc(
53 [](
const void* ptr,
void* context) {
54 delete reinterpret_cast<decltype(src)>(context);
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);
79 const auto dims = codec->dimensions();
80 auto info = SkImageInfo::Make(dims.width(), dims.height(),
81 kRGBA_8888_SkColorType, kPremul_SkAlphaType);
83 auto bitmap = std::make_shared<SkBitmap>();
84 if (!bitmap->tryAllocPixels(info)) {
85 VALIDATION_LOG <<
"Could not allocate arena for decompressing image.";
91 auto image = SkCodecs::DeferredImage(std::move(codec));
97 if (!image->readPixels(
nullptr, bitmap->pixmap(), 0, 0)) {
102 auto mapping = std::make_shared<fml::NonOwnedMapping>(
103 reinterpret_cast<const uint8_t*
>(bitmap->pixmap().addr()),
104 bitmap->pixmap().rowBytes() * bitmap->pixmap().height(),
105 [bitmap](
const uint8_t*
data,
size_t size)
mutable {
111 {bitmap->pixmap().dimensions().fWidth,
112 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