summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/CustomAsset.cpp
blob: 2b41d60a210d6b0baa1f5be4f2d8eecc2111a31c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoCommon/Assets/CustomAsset.h"

namespace VideoCommon
{
CustomAsset::CustomAsset(std::shared_ptr<CustomAssetLibrary> library,
                         const CustomAssetLibrary::AssetID& asset_id, u64 asset_handle)
    : m_owning_library(std::move(library)), m_asset_id(asset_id), m_handle(asset_handle)
{
}

std::size_t CustomAsset::Load()
{
  const auto load_information = LoadImpl(m_asset_id);
  if (load_information.m_bytes_loaded > 0)
  {
    std::lock_guard lk(m_info_lock);
    m_bytes_loaded = load_information.m_bytes_loaded;
    m_last_loaded_time = load_information.m_load_time;
    return m_bytes_loaded;
  }
  return 0;
}

std::size_t CustomAsset::Unload()
{
  UnloadImpl();
  std::size_t bytes_loaded = 0;
  {
    std::lock_guard lk(m_info_lock);
    bytes_loaded = m_bytes_loaded;
    m_bytes_loaded = 0;
  }
  return bytes_loaded;
}

CustomAssetLibrary::TimeType CustomAsset::GetLastWriteTime() const
{
  return m_owning_library->GetLastAssetWriteTime(m_asset_id);
}

const CustomAssetLibrary::TimeType& CustomAsset::GetLastLoadedTime() const
{
  std::lock_guard lk(m_info_lock);
  return m_last_loaded_time;
}

std::size_t CustomAsset::GetHandle() const
{
  return m_handle;
}

const CustomAssetLibrary::AssetID& CustomAsset::GetAssetId() const
{
  return m_asset_id;
}

std::size_t CustomAsset::GetByteSizeInMemory() const
{
  std::lock_guard lk(m_info_lock);
  return m_bytes_loaded;
}

}  // namespace VideoCommon