summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Resources/TextureDataResource.cpp
blob: 869055c5d4803de73458897e8aaef47894ae1dbc (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
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoCommon/Resources/TextureDataResource.h"

#include "VideoCommon/Assets/CustomAssetCache.h"

namespace VideoCommon
{
TextureDataResource::TextureDataResource(Resource::ResourceContext resource_context)
    : Resource(std::move(resource_context))
{
  m_texture_asset = m_resource_context.asset_cache->CreateAsset<TextureAsset>(
      m_resource_context.primary_asset_id, m_resource_context.asset_library, this);
}

std::shared_ptr<CustomTextureData> TextureDataResource::GetData() const
{
  return m_current_texture_data;
}

CustomAsset::TimeType TextureDataResource::GetLoadTime() const
{
  return m_current_time;
}

Resource::TaskComplete TextureDataResource::CollectPrimaryData()
{
  if (!m_texture_asset) [[unlikely]]
    return Resource::TaskComplete::Error;

  const auto last_load_time = m_texture_asset->GetLastLoadedTime();
  const auto asset = m_texture_asset->GetData();
  if (!asset)
    return Resource::TaskComplete::No;

  m_current_texture_data = asset;
  m_current_time = last_load_time;
  return Resource::TaskComplete::Yes;
}

void TextureDataResource::MarkAsActive()
{
  if (!m_texture_asset) [[unlikely]]
    return;
  m_resource_context.asset_cache->MarkAssetActive(m_texture_asset);
}

void TextureDataResource::MarkAsPending()
{
  if (!m_texture_asset) [[unlikely]]
    return;
  m_resource_context.asset_cache->MarkAssetPending(m_texture_asset);
}
}  // namespace VideoCommon