Search in sources :

Example 1 with TextureCompressionFormatAlias

use of com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias in project bundletool by google.

the class TextureCompressionFormatMatcher method matchesTargeting.

@Override
public boolean matchesTargeting(TextureCompressionFormatTargeting targeting) {
    // If there is no targeting, by definition the targeting is matched.
    if (targeting.equals(TextureCompressionFormatTargeting.getDefaultInstance())) {
        return true;
    }
    ImmutableSet<TextureCompressionFormatAlias> values = targeting.getValueList().stream().map(TextureCompressionFormat::getAlias).collect(toImmutableSet());
    ImmutableSet<TextureCompressionFormatAlias> alternatives = targeting.getAlternativesList().stream().map(TextureCompressionFormat::getAlias).collect(toImmutableSet());
    SetView<TextureCompressionFormatAlias> intersection = Sets.intersection(values, alternatives);
    checkArgument(intersection.isEmpty(), "Expected targeting values and alternatives to be mutually exclusive, but both contain: %s", intersection);
    // The device supported formats are sorted in the order of preference for texture formats.
    // We try looking for a given format in the values and alternatives.
    // If we find it in alternatives first, it means there is a better match.
    ImmutableSortedSet<TextureCompressionFormatAlias> orderedSupportedTextureCompressionFormats = sortTextureCompressionFormat(deviceSupportedTextureCompressionFormats);
    for (TextureCompressionFormatAlias textureCompressionFormatAlias : orderedSupportedTextureCompressionFormats) {
        if (values.contains(textureCompressionFormatAlias)) {
            // (because of the ordering).
            return true;
        }
        if (alternatives.contains(textureCompressionFormatAlias)) {
            // A better alternative exists.
            return false;
        }
    }
    // this targeting is the best that exists.
    if (values.isEmpty() && !alternatives.isEmpty()) {
        return true;
    }
    // targeting.
    return false;
}
Also used : TextureCompressionFormatAlias(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias)

Example 2 with TextureCompressionFormatAlias

use of com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias in project bundletool by google.

the class TextureCompressionFormatParityValidator method getSupportedTextureCompressionFormats.

private static SupportedTextureCompressionFormats getSupportedTextureCompressionFormats(BundleModule module) {
    // Extract targeted directories from entries (like done when generating assets targeting)
    ImmutableSet<TargetedDirectory> targetedDirectories = extractAssetsTargetedDirectories(module);
    // Inspect the targetings to extract texture compression formats.
    ImmutableSet<TextureCompressionFormatAlias> formats = extractTextureCompressionFormats(targetedDirectories);
    // Check if one or more targeted directories have "fallback" sibling directories.
    boolean hasFallback = targetedDirectories.stream().anyMatch(directory -> {
        Optional<AssetsDirectoryTargeting> targeting = directory.getTargeting(TargetingDimension.TEXTURE_COMPRESSION_FORMAT);
        if (targeting.isPresent()) {
            // Check if a sibling folder without texture targeting exists. If yes, this is
            // called a "fallback".
            TargetedDirectory siblingFallbackDirectory = directory.removeTargeting(TargetingDimension.TEXTURE_COMPRESSION_FORMAT);
            return module.findEntriesUnderPath(siblingFallbackDirectory.toZipPath()).findAny().isPresent();
        }
        return false;
    });
    return SupportedTextureCompressionFormats.create(formats, hasFallback);
}
Also used : AssetsDirectoryTargeting(com.android.bundle.Targeting.AssetsDirectoryTargeting) TextureCompressionFormatAlias(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias) TargetedDirectory(com.android.tools.build.bundletool.model.targeting.TargetedDirectory)

Aggregations

TextureCompressionFormatAlias (com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias)2 AssetsDirectoryTargeting (com.android.bundle.Targeting.AssetsDirectoryTargeting)1 TargetedDirectory (com.android.tools.build.bundletool.model.targeting.TargetedDirectory)1