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

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