@@ -329,69 +329,83 @@ bool Playground::OpenPlaygroundHere(SinglePassCallback pass_callback) {
329329 });
330330}
331331
332- std::optional<DecompressedImage> Playground::LoadFixtureImageRGBA (
333- const char * fixture_name) const {
334- if (!renderer_ || fixture_name == nullptr ) {
335- return std::nullopt ;
336- }
337-
338- auto compressed_image =
339- CompressedImage::Create (OpenAssetAsMapping (fixture_name));
332+ std::shared_ptr<CompressedImage> Playground::LoadFixtureImageCompressed (
333+ std::shared_ptr<fml::Mapping> mapping) const {
334+ auto compressed_image = CompressedImage::Create (std::move (mapping));
340335 if (!compressed_image) {
341336 VALIDATION_LOG << " Could not create compressed image." ;
337+ return nullptr ;
338+ }
339+
340+ return compressed_image;
341+ }
342+
343+ std::optional<DecompressedImage> Playground::DecodeImageRGBA (
344+ const std::shared_ptr<CompressedImage>& compressed) const {
345+ if (compressed == nullptr ) {
342346 return std::nullopt ;
343347 }
344348 // The decoded image is immediately converted into RGBA as that format is
345349 // known to be supported everywhere. For image sources that don't need 32
346350 // bit pixel strides, this is overkill. Since this is a test fixture we
347351 // aren't necessarily trying to eke out memory savings here and instead
348352 // favor simplicity.
349- auto image = compressed_image ->Decode ().ConvertToRGBA ();
353+ auto image = compressed ->Decode ().ConvertToRGBA ();
350354 if (!image.IsValid ()) {
351- VALIDATION_LOG << " Could not find fixture named " << fixture_name ;
355+ VALIDATION_LOG << " Could not decode image. " ;
352356 return std::nullopt ;
353357 }
354358
355359 return image;
356360}
357361
358362std::shared_ptr<Texture> Playground::CreateTextureForFixture (
359- const char * fixture_name ,
363+ DecompressedImage& decompressed_image ,
360364 bool enable_mipmapping) const {
361- auto image = LoadFixtureImageRGBA (fixture_name);
362- if (!image.has_value ()) {
363- return nullptr ;
364- }
365-
366365 auto texture_descriptor = TextureDescriptor{};
367366 texture_descriptor.storage_mode = StorageMode::kHostVisible ;
368367 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt ;
369- texture_descriptor.size = image-> GetSize ();
368+ texture_descriptor.size = decompressed_image. GetSize ();
370369 texture_descriptor.mip_count =
371- enable_mipmapping ? image-> GetSize ().MipCount () : 1u ;
370+ enable_mipmapping ? decompressed_image. GetSize ().MipCount () : 1u ;
372371
373372 auto texture = renderer_->GetContext ()->GetResourceAllocator ()->CreateTexture (
374373 texture_descriptor);
375374 if (!texture) {
376- VALIDATION_LOG << " Could not allocate texture for fixture " << fixture_name ;
375+ VALIDATION_LOG << " Could not allocate texture for fixture. " ;
377376 return nullptr ;
378377 }
379- texture->SetLabel (fixture_name);
380378
381- auto uploaded = texture->SetContents (image-> GetAllocation ());
379+ auto uploaded = texture->SetContents (decompressed_image. GetAllocation ());
382380 if (!uploaded) {
383- VALIDATION_LOG << " Could not upload texture to device memory for fixture "
384- << fixture_name;
381+ VALIDATION_LOG << " Could not upload texture to device memory for fixture." ;
385382 return nullptr ;
386383 }
387384 return texture;
388385}
389386
387+ std::shared_ptr<Texture> Playground::CreateTextureForFixture (
388+ std::shared_ptr<fml::Mapping> mapping,
389+ bool enable_mipmapping) const {
390+ auto image = DecodeImageRGBA (LoadFixtureImageCompressed (std::move (mapping)));
391+ if (!image.has_value ()) {
392+ return nullptr ;
393+ }
394+ return CreateTextureForFixture (image.value ());
395+ }
396+
397+ std::shared_ptr<Texture> Playground::CreateTextureForFixture (
398+ const char * fixture_name,
399+ bool enable_mipmapping) const {
400+ return CreateTextureForFixture (OpenAssetAsMapping (fixture_name));
401+ }
402+
390403std::shared_ptr<Texture> Playground::CreateTextureCubeForFixture (
391404 std::array<const char *, 6 > fixture_names) const {
392405 std::array<DecompressedImage, 6 > images;
393406 for (size_t i = 0 ; i < fixture_names.size (); i++) {
394- auto image = LoadFixtureImageRGBA (fixture_names[i]);
407+ auto image = DecodeImageRGBA (
408+ LoadFixtureImageCompressed (OpenAssetAsMapping (fixture_names[i])));
395409 if (!image.has_value ()) {
396410 return nullptr ;
397411 }
0 commit comments