GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/atlas/atlasresource.cpp Lines: 0 32 0.0 %
Date: 2021-03-17 Branches: 0 18 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#ifdef USE_OPENGL
23
24
#include "resources/atlas/atlasresource.h"
25
26
#include "resources/atlas/atlasmanager.h"
27
#include "resources/atlas/textureatlas.h"
28
29
#include "resources/resourcemanager/resourcemanager.h"
30
31
#include "debug.h"
32
33
AtlasResource::~AtlasResource()
34
{
35
    FOR_EACH (STD_VECTOR<TextureAtlas*>::iterator, it, atlases)
36
    {
37
        TextureAtlas *const atlas = *it;
38
        if (atlas != nullptr)
39
        {
40
            FOR_EACH (STD_VECTOR<AtlasItem*>::iterator, it2, atlas->items)
41
            {
42
                AtlasItem *const item = *it2;
43
                if (item != nullptr)
44
                {
45
                    Image *const image2 = item->image;
46
                    if (image2 != nullptr)
47
                        image2->decRef();
48
                    delete item;
49
                }
50
            }
51
            Image *const image = atlas->atlasImage;
52
            if (image != nullptr)
53
                image->decRef();
54
            delete atlas;
55
        }
56
    }
57
    ResourceManager::clearDeleted(false);
58
}
59
60
void AtlasResource::incRef()
61
{
62
    if (mRefCount == 0U)
63
        AtlasManager::injectToResources(this);
64
    Resource::incRef();
65
}
66
67
void AtlasResource::decRef()
68
{
69
    Resource::decRef();
70
    if (mRefCount == 0U)
71
        AtlasManager::moveToDeleted(this);
72
}
73
74
int AtlasResource::calcMemoryLocal() const
75
{
76
    return static_cast<int>(sizeof(AtlasResource)) +
77
        Resource::calcMemoryLocal() +
78
        static_cast<int>(atlases.capacity() * sizeof(TextureAtlas*));
79
}
80
81
int AtlasResource::calcMemoryChilds(const int level) const
82
{
83
    int sz = 0;
84
    FOR_EACH (STD_VECTOR<TextureAtlas*>::const_iterator, it, atlases)
85
    {
86
        TextureAtlas *const atlas = *it;
87
        sz += atlas->calcMemory(level + 1);
88
    }
89
    return sz;
90
}
91
92
#endif  // USE_OPENGL