summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/graphicsmanager.cpp7
-rw-r--r--src/render/sdl2softwaregraphics.h2
-rw-r--r--src/resources/sdl2softwarescreenshothelper.cpp79
-rw-r--r--src/resources/sdl2softwarescreenshothelper.h47
6 files changed, 137 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3cdf22ed8..b04034add 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -712,6 +712,8 @@ SET(SRCS
resources/sdl2imagehelper.h
resources/sdl2softwareimagehelper.cpp
resources/sdl2softwareimagehelper.h
+ resources/sdl2softwarescreenshothelper.cpp
+ resources/sdl2softwarescreenshothelper.h
resources/sdlimagehelper.cpp
resources/sdlimagehelper.h
resources/sdlmusic.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index ac8c054d9..4eb3066e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -366,6 +366,8 @@ SRC += events/actionevent.h \
resources/sdl2imagehelper.h \
resources/sdl2softwareimagehelper.cpp \
resources/sdl2softwareimagehelper.h \
+ resources/sdl2softwarescreenshothelper.cpp \
+ resources/sdl2softwarescreenshothelper.h \
resources/sdlimagehelper.cpp \
resources/sdlimagehelper.h \
resources/sdlmusic.cpp \
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp
index efaffd2d2..eea4ad67b 100644
--- a/src/graphicsmanager.cpp
+++ b/src/graphicsmanager.cpp
@@ -75,6 +75,7 @@
#include "render/sdl2softwaregraphics.h"
#include "resources/sdl2softwareimagehelper.h"
+#include "resources/sdl2softwarescreenshothelper.h"
#include "resources/surfaceimagehelper.h"
#endif
@@ -260,7 +261,7 @@ int GraphicsManager::detectGraphics()
imageHelper = new SDL2SoftwareImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
mainGraphics = new SDL2SoftwareGraphics; \
- screenshortHelper = new SdlScreenshotHelper;
+ screenshortHelper = new Sdl2SoftwareScreenshotHelper;
#define RENDER_SDL2_DEFAULT_INIT \
imageHelper = new SDLImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
@@ -391,7 +392,6 @@ void GraphicsManager::createRenderers()
// Setup image loading for the right image format
ImageHelper::setOpenGlMode(useOpenGL);
- screenshortHelper = new OpenGLScreenshotHelper;
// Create the graphics context
switch (useOpenGL)
{
@@ -411,10 +411,12 @@ void GraphicsManager::createRenderers()
imageHelper = new SDL2SoftwareImageHelper;
surfaceImageHelper = new SurfaceImageHelper;
mainGraphics = new SDL2SoftwareGraphics;
+ screenshortHelper = new Sdl2SoftwareScreenshotHelper;
#else
imageHelper = new SDLImageHelper;
surfaceImageHelper = imageHelper;
mainGraphics = new SDLGraphics;
+ screenshortHelper = new SdlScreenshotHelper;
#endif
break;
#ifdef USE_SDL2
@@ -423,6 +425,7 @@ void GraphicsManager::createRenderers()
surfaceImageHelper = new SurfaceImageHelper;
mainGraphics = new SDLGraphics;
mainGraphics->setRendererFlags(SDL_RENDERER_ACCELERATED);
+ screenshortHelper = new SdlScreenshotHelper;
break;
#endif
};
diff --git a/src/render/sdl2softwaregraphics.h b/src/render/sdl2softwaregraphics.h
index 91aff7329..81d92e474 100644
--- a/src/render/sdl2softwaregraphics.h
+++ b/src/render/sdl2softwaregraphics.h
@@ -42,6 +42,8 @@ struct SDL_Surface;
class SDL2SoftwareGraphics final : public Graphics
{
public:
+ friend class Sdl2SoftwareScreenshotHelper;
+
/**
* Constructor.
*/
diff --git a/src/resources/sdl2softwarescreenshothelper.cpp b/src/resources/sdl2softwarescreenshothelper.cpp
new file mode 100644
index 000000000..df797d7e7
--- /dev/null
+++ b/src/resources/sdl2softwarescreenshothelper.cpp
@@ -0,0 +1,79 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef USE_SDL2
+
+#include "resources/sdl2softwarescreenshothelper.h"
+
+#include "render/graphics.h"
+#include "render/sdl2softwaregraphics.h"
+
+#include "utils/sdlcheckutils.h"
+
+#include <SDL_endian.h>
+
+#include "debug.h"
+
+Sdl2SoftwareScreenshotHelper::Sdl2SoftwareScreenshotHelper() :
+ ScreenshotHelper()
+{
+}
+
+Sdl2SoftwareScreenshotHelper::~Sdl2SoftwareScreenshotHelper()
+{
+}
+
+void Sdl2SoftwareScreenshotHelper::prepare()
+{
+}
+
+SDL_Surface *Sdl2SoftwareScreenshotHelper::getScreenshot()
+{
+ if (!mainGraphics)
+ return nullptr;
+
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ const int rmask = 0xff000000;
+ const int gmask = 0x00ff0000;
+ const int bmask = 0x0000ff00;
+#else
+ const int rmask = 0x000000ff;
+ const int gmask = 0x0000ff00;
+ const int bmask = 0x00ff0000;
+#endif
+ const int amask = 0x00000000;
+
+ SDL_Surface *const screenshot = MSDL_CreateRGBSurface(SDL_SWSURFACE,
+ mainGraphics->mWidth, mainGraphics->mHeight,
+ 24,
+ rmask, gmask, bmask, amask);
+
+ if (screenshot)
+ {
+ SDL_BlitSurface(static_cast<SDL2SoftwareGraphics*>(
+ mainGraphics)->mSurface, nullptr, screenshot, nullptr);
+ }
+
+ return screenshot;
+}
+
+#endif // USE_SDL2
diff --git a/src/resources/sdl2softwarescreenshothelper.h b/src/resources/sdl2softwarescreenshothelper.h
new file mode 100644
index 000000000..018a57a90
--- /dev/null
+++ b/src/resources/sdl2softwarescreenshothelper.h
@@ -0,0 +1,47 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_SDL2SOFTWARESCREENSHOTHELPER_H
+#define RESOURCES_SDL2SOFTWARESCREENSHOTHELPER_H
+
+#ifdef USE_SDL2
+
+#include "resources/screenshothelper.h"
+
+#include "localconsts.h"
+
+class Sdl2SoftwareScreenshotHelper final : public ScreenshotHelper
+{
+ public:
+ Sdl2SoftwareScreenshotHelper();
+
+ A_DELETE_COPY(Sdl2SoftwareScreenshotHelper)
+
+ ~Sdl2SoftwareScreenshotHelper();
+
+ void prepare() override final;
+
+ SDL_Surface *getScreenshot() override final;
+};
+
+#endif // USE_SDL2
+#endif // RESOURCES_SDL2SOFTWARESCREENSHOTHELPER_H