CompressionSystemComponent.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "CompressionSystemComponent.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <Compression/CompressionLZ4API.h>
  11. #include <Compression/CompressionTypeIds.h>
  12. #include <Compression/DecompressionInterfaceAPI.h>
  13. #include "DecompressorLZ4Impl.h"
  14. #include <Clients/Streamer/DecompressorStackEntry.h>
  15. namespace CompressionLZ4
  16. {
  17. void RegisterDecompressorLZ4Interface()
  18. {
  19. // Register the lz4 decompressor with the decompression registrar
  20. if (auto decompressionRegistrar = Compression::DecompressionRegistrar::Get();
  21. decompressionRegistrar != nullptr)
  22. {
  23. auto compressionAlgorithmId = GetLZ4CompressionAlgorithmId();
  24. auto decompressorLz4 = AZStd::make_unique<DecompressorLZ4>();
  25. [[maybe_unused]] auto registerOutcome = decompressionRegistrar->RegisterDecompressionInterface(
  26. compressionAlgorithmId,
  27. AZStd::move(decompressorLz4));
  28. AZ_Error("Compression LZ4", bool{ registerOutcome }, "Registration of LZ4 Decompressor with the DecompressionRegistrar"
  29. " has failed with Id %u", compressionAlgorithmId);
  30. }
  31. }
  32. void UnregisterDecompressorLZ4Interface()
  33. {
  34. // Unregister the lz4 decompressor using the lz4 compression algorithm Id
  35. if (auto decompressionRegistrar = Compression::DecompressionRegistrar::Get();
  36. decompressionRegistrar != nullptr)
  37. {
  38. auto compressionAlgorithmId = GetLZ4CompressionAlgorithmId();
  39. [[maybe_unused]] bool unregisterOutcome = decompressionRegistrar->UnregisterDecompressionInterface(
  40. compressionAlgorithmId);
  41. AZ_Error("Compression LZ4", unregisterOutcome, "LZ4 Decompressor with Id %u is not registered with"
  42. " with DecompressionRegistrar", static_cast<AZ::u32>(compressionAlgorithmId));
  43. }
  44. }
  45. }
  46. namespace Compression
  47. {
  48. AZ_COMPONENT_IMPL(CompressionSystemComponent, "CompressionSystemComponent",
  49. CompressionSystemComponentTypeId);
  50. void CompressionSystemComponent::Reflect(AZ::ReflectContext* context)
  51. {
  52. // Reflect the Streamer DecompressionStackEntryConfig
  53. // to allow a DecompressionStackEntry to be loaded using JSON Serialization
  54. // from .setreg settings files
  55. DecompressorRegistrarConfig::Reflect(context);
  56. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  57. {
  58. serializeContext->Class<CompressionSystemComponent, AZ::Component>()
  59. ->Version(0)
  60. ;
  61. }
  62. }
  63. void CompressionSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  64. {
  65. provided.push_back(AZ_CRC_CE("CompressionService"));
  66. }
  67. void CompressionSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  68. {
  69. incompatible.push_back(AZ_CRC_CE("CompressionService"));
  70. }
  71. void CompressionSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  72. {
  73. }
  74. void CompressionSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  75. {
  76. }
  77. CompressionSystemComponent::CompressionSystemComponent()
  78. {
  79. if (CompressionInterface::Get() == nullptr)
  80. {
  81. CompressionInterface::Register(this);
  82. }
  83. }
  84. CompressionSystemComponent::~CompressionSystemComponent()
  85. {
  86. if (CompressionInterface::Get() == this)
  87. {
  88. CompressionInterface::Unregister(this);
  89. }
  90. }
  91. void CompressionSystemComponent::Init()
  92. {
  93. }
  94. void CompressionSystemComponent::Activate()
  95. {
  96. CompressionRequestBus::Handler::BusConnect();
  97. CompressionLZ4::RegisterDecompressorLZ4Interface();
  98. }
  99. void CompressionSystemComponent::Deactivate()
  100. {
  101. CompressionLZ4::UnregisterDecompressorLZ4Interface();
  102. CompressionRequestBus::Handler::BusDisconnect();
  103. }
  104. } // namespace Compression