Debian Codegraph @

Source/Core/VideoCommon/Assets/CustomAsset.cpp

raw symbols SCIP
1 // Copyright 2023 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "VideoCommon/Assets/CustomAsset.h"
5
6 #include <utility>
7
8 namespace VideoCommon
9 {
10 CustomAsset::CustomAsset(std::shared_ptr<CustomAssetLibrary> library,
11 CustomAssetLibrary::AssetID asset_id, u64 asset_handle)
12 : m_owning_library(std::move(library)), m_asset_id(std::move(asset_id)), m_handle(asset_handle)
13 {
14 }
15
16 std::size_t CustomAsset::Load()
17 {
18 std::lock_guard lk(m_info_lock);
19 // The load time needs to come from before the data is actually read.
20 // Using a time point from after the read marks the asset as more up-to-date than it actually is,
21 // and has potential to race (and not be updated) if a change happens immediately after load.
22 const auto load_time = ClockType::now();
23
24 const auto load_information = LoadImpl(m_asset_id);
25 if (load_information.bytes_loaded > 0)
26 {
27 m_bytes_loaded = load_information.bytes_loaded;
28 m_last_loaded_time = load_time;
29 return m_bytes_loaded;
30 }
31 return 0;
32 }
33
34 std::size_t CustomAsset::Unload()
35 {
36 std::lock_guard lk(m_info_lock);
37 UnloadImpl();
38 return std::exchange(m_bytes_loaded, 0);
39 }
40
41 CustomAsset::TimeType CustomAsset::GetLastLoadedTime() const
42 {
43 return m_last_loaded_time;
44 }
45
46 std::size_t CustomAsset::GetHandle() const
47 {
48 return m_handle;
49 }
50
51 const CustomAssetLibrary::AssetID& CustomAsset::GetAssetId() const
52 {
53 return m_asset_id;
54 }
55
56 } // namespace VideoCommon