GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/sdl2softwarescreenshothelper.cpp Lines: 0 14 0.0 %
Date: 2019-10-15 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-2019  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
#ifdef USE_SDL2
24
25
#include "resources/sdl2softwarescreenshothelper.h"
26
27
#include "render/sdl2softwaregraphics.h"
28
29
#include "utils/sdlcheckutils.h"
30
31
PRAGMA48(GCC diagnostic push)
32
PRAGMA48(GCC diagnostic ignored "-Wshadow")
33
#ifndef SDL_BIG_ENDIAN
34
#include <SDL_endian.h>
35
#endif  // SDL_BYTEORDER
36
PRAGMA48(GCC diagnostic pop)
37
38
#include "debug.h"
39
40
Sdl2SoftwareScreenshotHelper::Sdl2SoftwareScreenshotHelper() :
41
    ScreenshotHelper()
42
{
43
}
44
45
Sdl2SoftwareScreenshotHelper::~Sdl2SoftwareScreenshotHelper()
46
{
47
}
48
49
void Sdl2SoftwareScreenshotHelper::prepare()
50
{
51
}
52
53
SDL_Surface *Sdl2SoftwareScreenshotHelper::getScreenshot()
54
{
55
    if (!mainGraphics)
56
        return nullptr;
57
58
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
59
    const int rmask = 0xff000000;
60
    const int gmask = 0x00ff0000;
61
    const int bmask = 0x0000ff00;
62
#else  // SDL_BYTEORDER == SDL_BIG_ENDIAN
63
64
    const int rmask = 0x000000ff;
65
    const int gmask = 0x0000ff00;
66
    const int bmask = 0x00ff0000;
67
#endif  // SDL_BYTEORDER == SDL_BIG_ENDIAN
68
69
    const int amask = 0x00000000;
70
71
    SDL_Surface *const screenshot = MSDL_CreateRGBSurface(SDL_SWSURFACE,
72
        mainGraphics->mWidth, mainGraphics->mHeight,
73
        24,
74
        rmask, gmask, bmask, amask);
75
76
    if (screenshot)
77
    {
78
        SDL_BlitSurface(static_cast<SDL2SoftwareGraphics*>(
79
            mainGraphics)->mSurface, nullptr, screenshot, nullptr);
80
    }
81
82
    return screenshot;
83
}
84
85
#endif  // USE_SDL2