GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/render/surfacegraphics.cpp Lines: 0 49 0.0 %
Date: 2021-03-17 Branches: 0 22 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2019  The ManaPlus Developers
6
 *  Copyright (C) 2019-2021  Andrei Karas
7
 *
8
 *  This file is part of The ManaPlus Client.
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
#include "render/surfacegraphics.h"
25
26
#ifndef USE_SDL2
27
#include "resources/surfaceimagehelper.h"
28
#endif  // USE_SDL2
29
30
#include "resources/image/image.h"
31
32
#include "debug.h"
33
34
SurfaceGraphics::SurfaceGraphics() :
35
    Graphics(),
36
    mBlitMode(BlitMode::BLIT_NORMAL),
37
    mTarget(nullptr)
38
{
39
    mOpenGL = RENDER_SOFTWARE;
40
    mName = "Surface";
41
}
42
43
SurfaceGraphics::~SurfaceGraphics()
44
{
45
}
46
47
void SurfaceGraphics::drawImage(const Image *restrict const image,
48
                                int dstX, int dstY) restrict2
49
{
50
    FUNC_BLOCK("Graphics::drawImage", 1)
51
    // Check that preconditions for blitting are met.
52
    if (mTarget == nullptr ||
53
        image == nullptr ||
54
        image->mSDLSurface == nullptr)
55
    {
56
        return;
57
    }
58
59
    const SDL_Rect &imageRect = image->mBounds;
60
    SDL_Rect dstRect;
61
    SDL_Rect srcRect;
62
    dstRect.x = CAST_S16(dstX);
63
    dstRect.y = CAST_S16(dstY);
64
    srcRect.x = CAST_S16(imageRect.x);
65
    srcRect.y = CAST_S16(imageRect.y);
66
    srcRect.w = CAST_U16(imageRect.w);
67
    srcRect.h = CAST_U16(imageRect.h);
68
69
#ifdef USE_SDL2
70
    SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
71
#else  // USE_SDL2
72
73
    if (mBlitMode == BlitMode::BLIT_NORMAL)
74
    {
75
        SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
76
    }
77
    else
78
    {
79
        SurfaceImageHelper::combineSurface(image->mSDLSurface,
80
            &srcRect, mTarget, &dstRect);
81
    }
82
#endif  // USE_SDL2
83
}
84
85
void SurfaceGraphics::copyImage(const Image *restrict const image,
86
                                int dstX, int dstY) restrict2
87
{
88
    FUNC_BLOCK("Graphics::drawImage", 1)
89
    // Check that preconditions for blitting are met.
90
    if (mTarget == nullptr ||
91
        image == nullptr ||
92
        image->mSDLSurface == nullptr)
93
    {
94
        return;
95
    }
96
97
    const SDL_Rect &imageRect = image->mBounds;
98
    SDL_Rect dstRect;
99
    SDL_Rect srcRect;
100
    dstRect.x = CAST_S16(dstX);
101
    dstRect.y = CAST_S16(dstY);
102
    srcRect.x = CAST_S16(imageRect.x);
103
    srcRect.y = CAST_S16(imageRect.y);
104
    srcRect.w = CAST_U16(imageRect.w);
105
    srcRect.h = CAST_U16(imageRect.h);
106
107
#ifdef USE_SDL2
108
    // probably need change some flags
109
    SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
110
#else  // USE_SDL2
111
112
    SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
113
#endif  // USE_SDL2
114
}
115
116
void SurfaceGraphics::drawImageCached(const Image *restrict const image,
117
                                      int x, int y) restrict2
118
{
119
    FUNC_BLOCK("Graphics::drawImageCached", 1)
120
    // Check that preconditions for blitting are met.
121
    if (mTarget == nullptr ||
122
        image == nullptr ||
123
        image->mSDLSurface == nullptr)
124
    {
125
        return;
126
    }
127
128
    const SDL_Rect &rect = image->mBounds;
129
130
    SDL_Rect dstRect;
131
    SDL_Rect srcRect;
132
    dstRect.x = CAST_S16(x);
133
    dstRect.y = CAST_S16(y);
134
    srcRect.x = CAST_S16(rect.x);
135
    srcRect.y = CAST_S16(rect.y);
136
    srcRect.w = CAST_U16(rect.w);
137
    srcRect.h = CAST_U16(rect.h);
138
139
#ifdef USE_SDL2
140
    SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
141
#else  // USE_SDL2
142
143
    if (mBlitMode == BlitMode::BLIT_NORMAL)
144
    {
145
        SDL_BlitSurface(image->mSDLSurface, &srcRect, mTarget, &dstRect);
146
    }
147
    else
148
    {
149
        SurfaceImageHelper::combineSurface(image->mSDLSurface, &srcRect,
150
            mTarget, &dstRect);
151
    }
152
#endif  // USE_SDL2
153
}
154
155
void SurfaceGraphics::completeCache() restrict2
156
{
157
}