64 if (iptexture ==
nullptr || iptexture->embedded_image() ==
nullptr ||
65 iptexture->embedded_image()->bytes() ==
nullptr) {
69 auto embedded = iptexture->embedded_image();
71 uint8_t bytes_per_component = 0;
72 switch (embedded->component_type()) {
73 case fb::ComponentType::k8Bit:
74 bytes_per_component = 1;
76 case fb::ComponentType::k16Bit:
78 FML_LOG(WARNING) <<
"16 bit textures not yet supported.";
82 DecompressedImage::Format format;
83 switch (embedded->component_count()) {
85 format = DecompressedImage::Format::kGrey;
88 format = DecompressedImage::Format::kRGB;
91 format = DecompressedImage::Format::kRGBA;
94 FML_LOG(WARNING) <<
"Textures with " << embedded->component_count()
95 <<
" components are not supported." << std::endl;
98 if (embedded->bytes()->size() != bytes_per_component *
99 embedded->component_count() *
100 embedded->width() * embedded->height()) {
101 FML_LOG(WARNING) <<
"Embedded texture has an unexpected size. Skipping."
106 auto image_mapping = std::make_shared<fml::NonOwnedMapping>(
107 embedded->bytes()->Data(), embedded->bytes()->size());
108 auto decompressed_image =
109 DecompressedImage(
ISize(embedded->width(), embedded->height()), format,
113 auto texture_descriptor = TextureDescriptor{};
114 texture_descriptor.storage_mode = StorageMode::kHostVisible;
115 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
116 texture_descriptor.size = decompressed_image.GetSize();
118 texture_descriptor.mip_count = 1u;
120 auto texture = allocator.CreateTexture(texture_descriptor);
122 FML_LOG(ERROR) <<
"Could not allocate texture.";
126 auto uploaded = texture->SetContents(decompressed_image.GetAllocation());
128 FML_LOG(ERROR) <<
"Could not upload texture to device memory.";