GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/sdlscreenshothelper.cpp Lines: 0 13 0.0 %
Date: 2017-11-29 Branches: 0 4 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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "resources/sdlscreenshothelper.h"
24
25
#include "render/graphics.h"
26
27
#include "utils/sdlcheckutils.h"
28
29
PRAGMA48(GCC diagnostic push)
30
PRAGMA48(GCC diagnostic ignored "-Wshadow")
31
#ifndef SDL_BIG_ENDIAN
32
#include <SDL_endian.h>
33
#endif  // SDL_BYTEORDER
34
PRAGMA48(GCC diagnostic pop)
35
36
#include "debug.h"
37
38
SdlScreenshotHelper::SdlScreenshotHelper() :
39
    ScreenshotHelper()
40
{
41
}
42
43
SdlScreenshotHelper::~SdlScreenshotHelper()
44
{
45
}
46
47
void SdlScreenshotHelper::prepare()
48
{
49
}
50
51
SDL_Surface *SdlScreenshotHelper::getScreenshot()
52
{
53
    if (mainGraphics == nullptr)
54
        return nullptr;
55
56
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
57
    const int rmask = 0xff000000;
58
    const int gmask = 0x00ff0000;
59
    const int bmask = 0x0000ff00;
60
#else  // SDL_BYTEORDER == SDL_BIG_ENDIAN
61
62
    const int rmask = 0x000000ff;
63
    const int gmask = 0x0000ff00;
64
    const int bmask = 0x00ff0000;
65
#endif  // SDL_BYTEORDER == SDL_BIG_ENDIAN
66
67
    const int amask = 0x00000000;
68
69
    SDL_Surface *const screenshot = MSDL_CreateRGBSurface(SDL_SWSURFACE,
70
        mainGraphics->mWidth, mainGraphics->mHeight,
71
        24,
72
        rmask, gmask, bmask, amask);
73
74
#ifndef USE_SDL2
75
    if (screenshot != nullptr)
76
        SDL_BlitSurface(mainGraphics->mWindow, nullptr, screenshot, nullptr);
77
#endif  // USE_SDL2
78
79
    return screenshot;
80
}