TextureCache.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <functional>
  3. #include <map>
  4. #include <memory>
  5. #include <string>
  6. #include "TextureProvider.h"
  7. #include "WallpaperEngine/Render/Helpers/ContextAware.h"
  8. #include "WallpaperEngine/Render/RenderContext.h"
  9. using namespace WallpaperEngine::Render;
  10. namespace WallpaperEngine::Render {
  11. class AlbumTexture;
  12. namespace Helpers {
  13. class ContextAware;
  14. }
  15. class RenderContext;
  16. class TextureCache final : Helpers::ContextAware {
  17. public:
  18. explicit TextureCache (RenderContext& context);
  19. ~TextureCache () override;
  20. /**
  21. * Checks if the given texture was already loaded and returns it
  22. * If the texture was not loaded yet, it tries to load it from the container
  23. *
  24. * @param filename
  25. * @return
  26. */
  27. std::shared_ptr<const TextureProvider> resolve (const std::string& filename);
  28. /**
  29. * Registers a texture in the cache
  30. *
  31. * @param name
  32. * @param texture
  33. */
  34. void store (const std::string& name, std::shared_ptr<const TextureProvider> texture);
  35. private:
  36. /** The previous album thumbnail texture */
  37. std::shared_ptr<const AlbumTexture> m_previousThumbnail = nullptr;
  38. /** The current album thumbnail texture */
  39. std::shared_ptr<const AlbumTexture> m_currentThumbnail = nullptr;
  40. /** Cached textures */
  41. std::map<std::string, std::shared_ptr<const TextureProvider>> m_textureCache = {};
  42. /** The callback to de-register media events */
  43. std::function<void ()> m_mediaCallback;
  44. };
  45. } // namespace WallpaperEngine::Render