Debian Codegraph @

Source/Core/VideoCommon/Resources/TexturePool.cpp

raw symbols SCIP
1 // Copyright 2025 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "VideoCommon/Resources/TexturePool.h"
5
6 #include "Common/Logging/Log.h"
7
8 #include "VideoCommon/AbstractGfx.h"
9 #include "VideoCommon/AbstractTexture.h"
10
11 namespace VideoCommon
12 {
13 void TexturePool::Reset()
14 {
15 m_cache.clear();
16 }
17
18 std::unique_ptr<AbstractTexture> TexturePool::AllocateTexture(const TextureConfig& config)
19 {
20 const auto iter = m_cache.find(config);
21 if (iter != m_cache.end())
22 {
23 auto entry = std::move(iter->second);
24 m_cache.erase(iter);
25 return entry;
26 }
27
28 std::unique_ptr<AbstractTexture> texture = g_gfx->CreateTexture(config);
29 if (!texture)
30 {
31 ERROR_LOG_FMT(VIDEO, "Failed to allocate a {}x{}x{} texture", config.width, config.height,
32 config.layers);
33 return {};
34 }
35 return texture;
36 }
37
38 void TexturePool::ReleaseTexture(std::unique_ptr<AbstractTexture> texture)
39 {
40 auto config = texture->GetConfig();
41 (void)m_cache.emplace(config, std::move(texture));
42 }
43 } // namespace VideoCommon