65 if (iptexture ==
nullptr || iptexture->embedded_image() ==
nullptr ||
66 iptexture->embedded_image()->bytes() ==
nullptr) {
70 auto embedded = iptexture->embedded_image();
72 uint8_t bytes_per_component = 0;
73 switch (embedded->component_type()) {
74 case fb::ComponentType::k8Bit:
75 bytes_per_component = 1;
77 case fb::ComponentType::k16Bit:
79 FML_LOG(WARNING) <<
"16 bit textures not yet supported.";
83 DecompressedImage::Format format;
84 switch (embedded->component_count()) {
86 format = DecompressedImage::Format::kGrey;
89 format = DecompressedImage::Format::kRGB;
92 format = DecompressedImage::Format::kRGBA;
95 FML_LOG(WARNING) <<
"Textures with " << embedded->component_count()
96 <<
" components are not supported." << std::endl;
99 if (embedded->bytes()->size() != bytes_per_component *
100 embedded->component_count() *
101 embedded->width() * embedded->height()) {
102 FML_LOG(WARNING) <<
"Embedded texture has an unexpected size. Skipping."
107 auto image_mapping = std::make_shared<fml::NonOwnedMapping>(
108 embedded->bytes()->Data(), embedded->bytes()->size());
109 auto decompressed_image =
110 DecompressedImage(
ISize(embedded->width(), embedded->height()), format,
114 auto texture_descriptor = TextureDescriptor{};
115 texture_descriptor.storage_mode = StorageMode::kHostVisible;
116 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
117 texture_descriptor.size = decompressed_image.GetSize();
119 texture_descriptor.mip_count = 1u;
121 auto texture = allocator.CreateTexture(texture_descriptor);
123 FML_LOG(ERROR) <<
"Could not allocate texture.";
127 auto uploaded = texture->SetContents(decompressed_image.GetAllocation());
129 FML_LOG(ERROR) <<
"Could not upload texture to device memory.";