@@ -329,69 +329,83 @@ bool Playground::OpenPlaygroundHere(SinglePassCallback pass_callback) {
329
329
});
330
330
}
331
331
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));
340
335
if (!compressed_image) {
341
336
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 ) {
342
346
return std::nullopt;
343
347
}
344
348
// The decoded image is immediately converted into RGBA as that format is
345
349
// known to be supported everywhere. For image sources that don't need 32
346
350
// bit pixel strides, this is overkill. Since this is a test fixture we
347
351
// aren't necessarily trying to eke out memory savings here and instead
348
352
// favor simplicity.
349
- auto image = compressed_image ->Decode ().ConvertToRGBA ();
353
+ auto image = compressed ->Decode ().ConvertToRGBA ();
350
354
if (!image.IsValid ()) {
351
- VALIDATION_LOG << " Could not find fixture named " << fixture_name ;
355
+ VALIDATION_LOG << " Could not decode image. " ;
352
356
return std::nullopt;
353
357
}
354
358
355
359
return image;
356
360
}
357
361
358
362
std::shared_ptr<Texture> Playground::CreateTextureForFixture (
359
- const char * fixture_name ,
363
+ DecompressedImage& decompressed_image ,
360
364
bool enable_mipmapping) const {
361
- auto image = LoadFixtureImageRGBA (fixture_name);
362
- if (!image.has_value ()) {
363
- return nullptr ;
364
- }
365
-
366
365
auto texture_descriptor = TextureDescriptor{};
367
366
texture_descriptor.storage_mode = StorageMode::kHostVisible ;
368
367
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt ;
369
- texture_descriptor.size = image-> GetSize ();
368
+ texture_descriptor.size = decompressed_image. GetSize ();
370
369
texture_descriptor.mip_count =
371
- enable_mipmapping ? image-> GetSize ().MipCount () : 1u ;
370
+ enable_mipmapping ? decompressed_image. GetSize ().MipCount () : 1u ;
372
371
373
372
auto texture = renderer_->GetContext ()->GetResourceAllocator ()->CreateTexture (
374
373
texture_descriptor);
375
374
if (!texture) {
376
- VALIDATION_LOG << " Could not allocate texture for fixture " << fixture_name ;
375
+ VALIDATION_LOG << " Could not allocate texture for fixture. " ;
377
376
return nullptr ;
378
377
}
379
- texture->SetLabel (fixture_name);
380
378
381
- auto uploaded = texture->SetContents (image-> GetAllocation ());
379
+ auto uploaded = texture->SetContents (decompressed_image. GetAllocation ());
382
380
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." ;
385
382
return nullptr ;
386
383
}
387
384
return texture;
388
385
}
389
386
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
+
390
403
std::shared_ptr<Texture> Playground::CreateTextureCubeForFixture (
391
404
std::array<const char *, 6 > fixture_names) const {
392
405
std::array<DecompressedImage, 6 > images;
393
406
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])));
395
409
if (!image.has_value ()) {
396
410
return nullptr ;
397
411
}
0 commit comments