118 {
120 if (!descriptor) {
121 std::string decode_error("Invalid descriptor (should never happen)");
123 return DecompressResult{.decode_error = decode_error};
124 }
125
126 target_size.
set(std::min(
static_cast<int32_t
>(max_texture_size.
width),
127 target_size.
width()),
128 std::min(
static_cast<int32_t
>(max_texture_size.
height),
130
131 const SkISize source_size = descriptor->image_info().dimensions();
132 auto decode_size = source_size;
133 if (descriptor->is_compressed()) {
134 decode_size = descriptor->get_scaled_dimensions(std::max(
135 static_cast<float>(target_size.
width()) / source_size.
width(),
136 static_cast<float>(target_size.
height()) / source_size.
height()));
137 }
138
139
140
141
142
143 const auto base_image_info = descriptor->image_info();
144 const bool is_wide_gamut =
145 supports_wide_gamut ? IsWideGamut(base_image_info.colorSpace()) :
false;
149 if (is_wide_gamut) {
153 image_info =
154 base_image_info.
makeWH(decode_size.width(), decode_size.height())
158 } else {
159 image_info =
160 base_image_info.
makeWH(decode_size.width(), decode_size.height())
164 }
165
166 const auto pixel_format =
168 if (!pixel_format.has_value()) {
170 "Codec pixel format is not supported (SkColorType=%d)",
173 return DecompressResult{.decode_error = decode_error};
174 }
175
176 auto bitmap = std::make_shared<SkBitmap>();
177 bitmap->setInfo(image_info);
178 auto bitmap_allocator = std::make_shared<ImpellerAllocator>(allocator);
179
180 if (descriptor->is_compressed()) {
181 if (!
bitmap->tryAllocPixels(bitmap_allocator.get())) {
182 std::string decode_error(
183 "Could not allocate intermediate for image decompression.");
185 return DecompressResult{.decode_error = decode_error};
186 }
187
188 if (!descriptor->get_pixels(
bitmap->pixmap())) {
189 std::string decode_error("Could not decompress image.");
191 return DecompressResult{.decode_error = decode_error};
192 }
193 } else {
194 auto temp_bitmap = std::make_shared<SkBitmap>();
195 temp_bitmap->setInfo(base_image_info);
197 base_image_info, descriptor->row_bytes(), descriptor->data());
198 temp_bitmap->setPixelRef(pixel_ref, 0, 0);
199
200 if (!
bitmap->tryAllocPixels(bitmap_allocator.get())) {
201 std::string decode_error(
202 "Could not allocate intermediate for pixel conversion.");
204 return DecompressResult{.decode_error = decode_error};
205 }
206 temp_bitmap->readPixels(
bitmap->pixmap());
208 }
209
210 if (
bitmap->dimensions() == target_size) {
211 std::shared_ptr<impeller::DeviceBuffer>
buffer =
212 bitmap_allocator->GetDeviceBuffer();
214 return DecompressResult{.decode_error = "Unable to get device buffer"};
215 }
217
218 return DecompressResult{.device_buffer = std::move(
buffer),
220 .image_info =
bitmap->info()};
221 }
222
223
224
225
226
228 const auto scaled_image_info = image_info.
makeDimensions(target_size);
229
230 auto scaled_bitmap = std::make_shared<SkBitmap>();
231 auto scaled_allocator = std::make_shared<ImpellerAllocator>(allocator);
232 scaled_bitmap->setInfo(scaled_image_info);
233 if (!scaled_bitmap->tryAllocPixels(scaled_allocator.get())) {
234 std::string decode_error(
235 "Could not allocate scaled bitmap for image decompression.");
237 return DecompressResult{.decode_error = decode_error};
238 }
239 if (!
bitmap->pixmap().scalePixels(
240 scaled_bitmap->pixmap(),
242 FML_LOG(
ERROR) <<
"Could not scale decoded bitmap data.";
243 }
244 scaled_bitmap->setImmutable();
245
246 std::shared_ptr<impeller::DeviceBuffer>
buffer =
247 scaled_allocator->GetDeviceBuffer();
249
251 return DecompressResult{.decode_error = "Unable to get device buffer"};
252 }
253 return DecompressResult{.device_buffer = std::move(
buffer),
254 .sk_bitmap = scaled_bitmap,
255 .image_info = scaled_bitmap->info()};
256}
@ kOpaque_SkAlphaType
pixel is opaque
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
static sk_sp< SkColorSpace > MakeSRGB()
#define FML_DLOG(severity)
#define FML_LOG(severity)
SK_API sk_sp< SkPixelRef > MakeWithData(const SkImageInfo &, size_t rowBytes, sk_sp< SkData > data)
static SkAlphaType ChooseCompatibleAlphaType(SkAlphaType type)
static SkColorType ChooseCompatibleColorType(SkColorType type)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
std::optional< impeller::PixelFormat > ToPixelFormat(SkColorType type)
std::string SPrintF(const char *format,...)
constexpr int32_t width() const
void set(int32_t w, int32_t h)
constexpr int32_t height() const
SkImageInfo makeWH(int newWidth, int newHeight) const
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
SkImageInfo makeDimensions(SkISize newSize) const
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
SkColorType colorType() const
SkImageInfo makeColorType(SkColorType newColorType) const
#define TRACE_EVENT0(category_group, name)