summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game.cpp9
-rw-r--r--src/graphicsmanager.cpp17
-rw-r--r--src/render/graphics.h11
-rw-r--r--src/render/graphicsdef.hpp5
-rw-r--r--src/render/imagegraphics.h3
-rw-r--r--src/render/mobileopengl2graphics.cpp57
-rw-r--r--src/render/mobileopenglgraphics.cpp57
-rw-r--r--src/render/modernopenglgraphics.cpp57
-rw-r--r--src/render/normalopenglgraphics.cpp58
-rw-r--r--src/render/nullopenglgraphics.cpp9
-rw-r--r--src/render/openglgraphicsdef.hpp2
-rw-r--r--src/render/safeopenglgraphics.cpp56
-rw-r--r--src/render/sdl2graphics.cpp22
-rw-r--r--src/render/sdl2softwaregraphics.cpp22
-rw-r--r--src/render/sdlgraphics.cpp22
-rw-r--r--src/render/surfacegraphics.h3
-rw-r--r--src/resources/openglscreenshothelper.cpp14
-rw-r--r--src/resources/openglscreenshothelper.h12
-rw-r--r--src/resources/screenshothelper.h8
-rw-r--r--src/resources/sdlscreenshothelper.cpp11
-rw-r--r--src/resources/sdlscreenshothelper.h12
-rw-r--r--src/test/testlauncher.cpp3
22 files changed, 52 insertions, 418 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 4fd84cfcb..efc4bd0f0 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -110,6 +110,7 @@
#include "resources/imagewriter.h"
#include "resources/mapreader.h"
#include "resources/resourcemanager.h"
+#include "resources/screenshothelper.h"
#include "resources/db/mapdb.h"
@@ -483,7 +484,7 @@ void Game::addWatermark()
bool Game::createScreenshot()
{
- if (!mainGraphics)
+ if (!mainGraphics || !screenshortHelper)
return false;
SDL_Surface *screenshot = nullptr;
@@ -491,16 +492,16 @@ bool Game::createScreenshot()
if (!config.getBoolValue("showip") && gui)
{
mainGraphics->setSecure(true);
- mainGraphics->prepareScreenshot();
+ screenshortHelper->prepare();
gui->draw();
addWatermark();
- screenshot = mainGraphics->getScreenshot();
+ screenshot = screenshortHelper->getScreenshot();
mainGraphics->setSecure(false);
}
else
{
addWatermark();
- screenshot = mainGraphics->getScreenshot();
+ screenshot = screenshortHelper->getScreenshot();
}
if (!screenshot)
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp
index 129ad966d..efaffd2d2 100644
--- a/src/graphicsmanager.cpp
+++ b/src/graphicsmanager.cpp
@@ -61,6 +61,7 @@
#ifdef USE_OPENGL
#include "resources/fboinfo.h"
#include "resources/openglimagehelper.h"
+#include "resources/openglscreenshothelper.h"
#ifndef ANDROID
#include "resources/safeopenglimagehelper.h"
#endif // ANDROID
@@ -68,6 +69,7 @@
#endif // USE_OPENGL
#include "resources/sdlimagehelper.h"
+#include "resources/sdlscreenshothelper.h"
#ifdef USE_SDL2
#include "render/sdl2softwaregraphics.h"
@@ -100,6 +102,8 @@ GraphicsManager graphicsManager;
RenderType openGLMode = RENDER_SOFTWARE;
+ScreenshotHelper *screenshortHelper = nullptr;
+
const int densitySize = 6;
const std::string densityNames[] =
@@ -255,18 +259,21 @@ int GraphicsManager::detectGraphics()
#define RENDER_SOFTWARE_INIT \
imageHelper = new SDL2SoftwareImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
- mainGraphics = new SDL2SoftwareGraphics;
+ mainGraphics = new SDL2SoftwareGraphics; \
+ screenshortHelper = new SdlScreenshotHelper;
#define RENDER_SDL2_DEFAULT_INIT \
imageHelper = new SDLImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
mainGraphics = new SDLGraphics; \
+ screenshortHelper = new SdlScreenshotHelper; \
mainGraphics->setRendererFlags(SDL_RENDERER_ACCELERATED); \
mUseTextureSampler = false;
#else // USE_SDL2
#define RENDER_SOFTWARE_INIT \
imageHelper = new SDLImageHelper; \
surfaceImageHelper = imageHelper; \
- mainGraphics = new SDLGraphics;
+ mainGraphics = new SDLGraphics; \
+ screenshortHelper = new SdlScreenshotHelper;
#define RENDER_SDL2_DEFAULT_INIT
#endif // USE_SDL2
@@ -278,11 +285,13 @@ int GraphicsManager::detectGraphics()
imageHelper = new OpenGLImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
mainGraphics = new NormalOpenGLGraphics; \
+ screenshortHelper = new OpenGLScreenshotHelper; \
mUseTextureSampler = true;
#define RENDER_MODERN_OPENGL_INIT \
imageHelper = new OpenGLImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
mainGraphics = new ModernOpenGLGraphics; \
+ screenshortHelper = new OpenGLScreenshotHelper; \
mUseTextureSampler = true;
#endif // defined(ANDROID) || defined(__native_client__)
@@ -294,11 +303,13 @@ int GraphicsManager::detectGraphics()
imageHelper = new SafeOpenGLImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
mainGraphics = new SafeOpenGLGraphics; \
+ screenshortHelper = new OpenGLScreenshotHelper; \
mUseTextureSampler = false;
#define RENDER_GLES2_OPENGL_INIT \
imageHelper = new OpenGLImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
mainGraphics = new MobileOpenGL2Graphics; \
+ screenshortHelper = new OpenGLScreenshotHelper; \
mUseTextureSampler = false;
#endif // defined(ANDROID)
@@ -309,6 +320,7 @@ int GraphicsManager::detectGraphics()
imageHelper = new OpenGLImageHelper; \
surfaceImageHelper = new SurfaceImageHelper; \
mainGraphics = new MobileOpenGLGraphics; \
+ screenshortHelper = new OpenGLScreenshotHelper; \
mUseTextureSampler = false;
#endif // defined(__native_client__)
@@ -379,6 +391,7 @@ void GraphicsManager::createRenderers()
// Setup image loading for the right image format
ImageHelper::setOpenGlMode(useOpenGL);
+ screenshortHelper = new OpenGLScreenshotHelper;
// Create the graphics context
switch (useOpenGL)
{
diff --git a/src/render/graphics.h b/src/render/graphics.h
index f8d10a832..0f0e14776 100644
--- a/src/render/graphics.h
+++ b/src/render/graphics.h
@@ -105,6 +105,9 @@ struct SDL_Window;
class Graphics notfinal
{
public:
+#ifdef USE_OPENGL
+ friend class OpenGLScreenshotHelper;
+#endif
friend class SdlScreenshotHelper;
A_DELETE_COPY(Graphics)
@@ -246,14 +249,6 @@ class Graphics notfinal
*/
int getHeight() const A_WARN_UNUSED;
- /**
- * Takes a screenshot and returns it as SDL surface.
- */
- virtual SDL_Surface *getScreenshot() A_WARN_UNUSED = 0;
-
- virtual void prepareScreenshot()
- { }
-
int getMemoryUsage() const A_WARN_UNUSED;
virtual void drawNet(const int x1, const int y1,
diff --git a/src/render/graphicsdef.hpp b/src/render/graphicsdef.hpp
index fb90c2fb4..4c77b46d5 100644
--- a/src/render/graphicsdef.hpp
+++ b/src/render/graphicsdef.hpp
@@ -84,11 +84,6 @@ public:
void updateScreen() override final;
- /**
- * Takes a screenshot and returns it as SDL surface.
- */
- SDL_Surface *getScreenshot() override final A_WARN_UNUSED;
-
void calcWindow(ImageCollection *const vertCol,
const int x, const int y,
const int w, const int h,
diff --git a/src/render/imagegraphics.h b/src/render/imagegraphics.h
index 8957543d4..df07bdacd 100644
--- a/src/render/imagegraphics.h
+++ b/src/render/imagegraphics.h
@@ -131,9 +131,6 @@ class ImegeGraphics final : public Graphics
void updateScreen() override final
{ }
- SDL_Surface *getScreenshot() override final A_WARN_UNUSED
- { return nullptr; }
-
void drawNet(const int x1 A_UNUSED,
const int y1 A_UNUSED,
const int x2 A_UNUSED,
diff --git a/src/render/mobileopengl2graphics.cpp b/src/render/mobileopengl2graphics.cpp
index 979d17224..9db0f07f4 100644
--- a/src/render/mobileopengl2graphics.cpp
+++ b/src/render/mobileopengl2graphics.cpp
@@ -860,63 +860,6 @@ void MobileOpenGL2Graphics::endDraw()
popClipArea();
}
-void MobileOpenGL2Graphics::prepareScreenshot()
-{
- if (config.getBoolValue("usefbo"))
- graphicsManager.createFBO(mRect.w, mRect.h, &mFbo);
-}
-
-SDL_Surface* MobileOpenGL2Graphics::getScreenshot()
-{
- const int h = mRect.h;
- const int w = mRect.w - (mRect.w % 4);
- GLint pack = 1;
-
- SDL_Surface *const screenshot = MSDL_CreateRGBSurface(
- SDL_SWSURFACE, w, h, 24,
- 0xff0000, 0x00ff00, 0x0000ff, 0x000000);
-
- if (!screenshot)
- return nullptr;
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_LockSurface(screenshot);
-
- const size_t lineSize = 3 * w;
- GLubyte *const buf = new GLubyte[lineSize];
-
- // Grap the pixel buffer and write it to the SDL surface
- mglGetIntegerv(GL_PACK_ALIGNMENT, &pack);
- mglPixelStorei(GL_PACK_ALIGNMENT, 1);
- mglReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
-
- // Flip the screenshot, as OpenGL has 0,0 in bottom left
- const int h2 = h / 2;
- for (int i = 0; i < h2; i++)
- {
- GLubyte *const top = static_cast<GLubyte*>(
- screenshot->pixels) + lineSize * i;
- GLubyte *const bot = static_cast<GLubyte*>(
- screenshot->pixels) + lineSize * (h - 1 - i);
-
- memcpy(buf, top, lineSize);
- memcpy(top, bot, lineSize);
- memcpy(bot, buf, lineSize);
- }
-
- delete [] buf;
-
- if (config.getBoolValue("usefbo"))
- graphicsManager.deleteFBO(&mFbo);
-
- mglPixelStorei(GL_PACK_ALIGNMENT, pack);
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_UnlockSurface(screenshot);
-
- return screenshot;
-}
-
void MobileOpenGL2Graphics::pushClipArea(const Rect &area)
{
Graphics::pushClipArea(area);
diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp
index 0b3d4e4dc..ce7501e27 100644
--- a/src/render/mobileopenglgraphics.cpp
+++ b/src/render/mobileopenglgraphics.cpp
@@ -938,63 +938,6 @@ void MobileOpenGLGraphics::endDraw()
popClipArea();
}
-void MobileOpenGLGraphics::prepareScreenshot()
-{
- if (config.getBoolValue("usefbo"))
- graphicsManager.createFBO(mRect.w, mRect.h, &mFbo);
-}
-
-SDL_Surface* MobileOpenGLGraphics::getScreenshot()
-{
- const int h = mRect.h;
- const int w = mRect.w - (mRect.w % 4);
- GLint pack = 1;
-
- SDL_Surface *const screenshot = MSDL_CreateRGBSurface(
- SDL_SWSURFACE, w, h, 24,
- 0xff0000, 0x00ff00, 0x0000ff, 0x000000);
-
- if (!screenshot)
- return nullptr;
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_LockSurface(screenshot);
-
- const size_t lineSize = 3 * w;
- GLubyte *const buf = new GLubyte[lineSize];
-
- // Grap the pixel buffer and write it to the SDL surface
- mglGetIntegerv(GL_PACK_ALIGNMENT, &pack);
- mglPixelStorei(GL_PACK_ALIGNMENT, 1);
- mglReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
-
- // Flip the screenshot, as OpenGL has 0,0 in bottom left
- const int h2 = h / 2;
- for (int i = 0; i < h2; i++)
- {
- GLubyte *const top = static_cast<GLubyte*>(
- screenshot->pixels) + lineSize * i;
- GLubyte *const bot = static_cast<GLubyte*>(
- screenshot->pixels) + lineSize * (h - 1 - i);
-
- memcpy(buf, top, lineSize);
- memcpy(top, bot, lineSize);
- memcpy(bot, buf, lineSize);
- }
-
- delete [] buf;
-
- if (config.getBoolValue("usefbo"))
- graphicsManager.deleteFBO(&mFbo);
-
- mglPixelStorei(GL_PACK_ALIGNMENT, pack);
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_UnlockSurface(screenshot);
-
- return screenshot;
-}
-
void MobileOpenGLGraphics::pushClipArea(const Rect &area)
{
int transX = 0;
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index fc59a7413..1ff55045c 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -849,63 +849,6 @@ void ModernOpenGLGraphics::endDraw()
popClipArea();
}
-void ModernOpenGLGraphics::prepareScreenshot()
-{
- if (config.getBoolValue("usefbo"))
- graphicsManager.createFBO(mRect.w, mRect.h, &mFbo);
-}
-
-SDL_Surface* ModernOpenGLGraphics::getScreenshot()
-{
- const int h = mRect.h;
- const int w = mRect.w - (mRect.w % 4);
- GLint pack = 1;
-
- SDL_Surface *const screenshot = MSDL_CreateRGBSurface(
- SDL_SWSURFACE, w, h, 24,
- 0xff0000, 0x00ff00, 0x0000ff, 0x000000);
-
- if (!screenshot)
- return nullptr;
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_LockSurface(screenshot);
-
- const size_t lineSize = 3 * w;
- GLubyte *const buf = new GLubyte[lineSize];
-
- // Grap the pixel buffer and write it to the SDL surface
- mglGetIntegerv(GL_PACK_ALIGNMENT, &pack);
- mglPixelStorei(GL_PACK_ALIGNMENT, 1);
- mglReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
-
- // Flip the screenshot, as OpenGL has 0,0 in bottom left
- const int h2 = h / 2;
- for (int i = 0; i < h2; i++)
- {
- GLubyte *const top = static_cast<GLubyte*>(
- screenshot->pixels) + lineSize * i;
- GLubyte *const bot = static_cast<GLubyte*>(
- screenshot->pixels) + lineSize * (h - 1 - i);
-
- memcpy(buf, top, lineSize);
- memcpy(top, bot, lineSize);
- memcpy(bot, buf, lineSize);
- }
-
- delete [] buf;
-
- if (config.getBoolValue("usefbo"))
- graphicsManager.deleteFBO(&mFbo);
-
- mglPixelStorei(GL_PACK_ALIGNMENT, pack);
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_UnlockSurface(screenshot);
-
- return screenshot;
-}
-
void ModernOpenGLGraphics::pushClipArea(const Rect &area)
{
Graphics::pushClipArea(area);
diff --git a/src/render/normalopenglgraphics.cpp b/src/render/normalopenglgraphics.cpp
index f58e10f92..b86859f6d 100644
--- a/src/render/normalopenglgraphics.cpp
+++ b/src/render/normalopenglgraphics.cpp
@@ -1268,64 +1268,6 @@ void NormalOpenGLGraphics::endDraw()
popClipArea();
}
-void NormalOpenGLGraphics::prepareScreenshot()
-{
- if (config.getBoolValue("usefbo"))
- graphicsManager.createFBO(mRect.w, mRect.h, &mFbo);
-}
-
-SDL_Surface* NormalOpenGLGraphics::getScreenshot()
-{
- const int h = mRect.h;
- const int w = mRect.w - (mRect.w % 4);
- GLint pack = 1;
-
- SDL_Surface *const screenshot = MSDL_CreateRGBSurface(
- SDL_SWSURFACE,
- w, h, 24,
- 0xff0000, 0x00ff00, 0x0000ff, 0x000000);
-
- if (!screenshot)
- return nullptr;
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_LockSurface(screenshot);
-
- // Grap the pixel buffer and write it to the SDL surface
- glGetIntegerv(GL_PACK_ALIGNMENT, &pack);
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
-
- // Flip the screenshot, as OpenGL has 0,0 in bottom left
- const size_t lineSize = 3 * w;
- GLubyte *const buf = new GLubyte[lineSize];
-
- const int h2 = h / 2;
- for (int i = 0; i < h2; i++)
- {
- GLubyte *const top = static_cast<GLubyte *const>(
- screenshot->pixels) + lineSize * i;
- GLubyte *const bot = static_cast<GLubyte *const>(
- screenshot->pixels) + lineSize * (h - 1 - i);
-
- memcpy(buf, top, lineSize);
- memcpy(top, bot, lineSize);
- memcpy(bot, buf, lineSize);
- }
-
- delete [] buf;
-
- if (config.getBoolValue("usefbo"))
- graphicsManager.deleteFBO(&mFbo);
-
- glPixelStorei(GL_PACK_ALIGNMENT, pack);
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_UnlockSurface(screenshot);
-
- return screenshot;
-}
-
void NormalOpenGLGraphics::pushClipArea(const Rect &area)
{
int transX = 0;
diff --git a/src/render/nullopenglgraphics.cpp b/src/render/nullopenglgraphics.cpp
index 27013f93b..9be3626a8 100644
--- a/src/render/nullopenglgraphics.cpp
+++ b/src/render/nullopenglgraphics.cpp
@@ -956,15 +956,6 @@ void NullOpenGLGraphics::endDraw()
popClipArea();
}
-void NullOpenGLGraphics::prepareScreenshot()
-{
-}
-
-SDL_Surface* NullOpenGLGraphics::getScreenshot()
-{
- return nullptr;
-}
-
void NullOpenGLGraphics::pushClipArea(const Rect &area)
{
int transX = 0;
diff --git a/src/render/openglgraphicsdef.hpp b/src/render/openglgraphicsdef.hpp
index 90f65af06..7f100f832 100644
--- a/src/render/openglgraphicsdef.hpp
+++ b/src/render/openglgraphicsdef.hpp
@@ -30,8 +30,6 @@ public:
static void dumpSettings();
- void prepareScreenshot() override final;
-
int getMemoryUsage() A_WARN_UNUSED;
void updateTextureFormat();
diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp
index f2609c299..143594733 100644
--- a/src/render/safeopenglgraphics.cpp
+++ b/src/render/safeopenglgraphics.cpp
@@ -517,62 +517,6 @@ void SafeOpenGLGraphics::endDraw()
popClipArea();
}
-void SafeOpenGLGraphics::prepareScreenshot()
-{
- if (config.getBoolValue("usefbo"))
- graphicsManager.createFBO(mRect.w, mRect.h, &mFbo);
-}
-
-SDL_Surface* SafeOpenGLGraphics::getScreenshot()
-{
- const int h = mRect.h;
- const int w = mRect.w - (mRect.w % 4);
- GLint pack = 1;
-
- SDL_Surface *const screenshot = MSDL_CreateRGBSurface(
- SDL_SWSURFACE, w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000);
-
- if (!screenshot || !screenshot->pixels)
- return nullptr;
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_LockSurface(screenshot);
-
- // Grap the pixel buffer and write it to the SDL surface
- glGetIntegerv(GL_PACK_ALIGNMENT, &pack);
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
-
- // Flip the screenshot, as OpenGL has 0,0 in bottom left
- size_t lineSize = 3 * w;
- GLubyte* buf = new GLubyte[lineSize];
-
- const int h2 = h / 2;
- for (int i = 0; i < h2; i++)
- {
- GLubyte *const top = static_cast<GLubyte*>(
- screenshot->pixels) + lineSize * i;
- GLubyte *const bot = static_cast<GLubyte*>(
- screenshot->pixels) + lineSize * (h - 1 - i);
-
- memcpy(buf, top, lineSize);
- memcpy(top, bot, lineSize);
- memcpy(bot, buf, lineSize);
- }
-
- delete [] buf;
-
- if (config.getBoolValue("usefbo"))
- graphicsManager.deleteFBO(&mFbo);
-
- glPixelStorei(GL_PACK_ALIGNMENT, pack);
-
- if (SDL_MUSTLOCK(screenshot))
- SDL_UnlockSurface(screenshot);
-
- return screenshot;
-}
-
void SafeOpenGLGraphics::pushClipArea(const Rect &area)
{
int transX = 0;
diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp
index 7bad93889..fa0c4a0d1 100644
--- a/src/render/sdl2graphics.cpp
+++ b/src/render/sdl2graphics.cpp
@@ -606,28 +606,6 @@ void SDLGraphics::updateScreen()
BLOCK_END("Graphics::updateScreen")
}
-SDL_Surface *SDLGraphics::getScreenshot()
-{
-#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,
- mRect.w, mRect.h, 24, rmask, gmask, bmask, amask);
-
-// if (screenshot)
-// SDL_BlitSurface(mWindow, nullptr, screenshot, nullptr);
-
- return screenshot;
-}
-
void SDLGraphics::calcWindow(ImageCollection *const vertCol,
const int x, const int y,
const int w, const int h,
diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp
index 3afadd27c..653fd5a68 100644
--- a/src/render/sdl2softwaregraphics.cpp
+++ b/src/render/sdl2softwaregraphics.cpp
@@ -790,28 +790,6 @@ void SDL2SoftwareGraphics::updateScreen()
BLOCK_END("Graphics::updateScreen")
}
-SDL_Surface *SDL2SoftwareGraphics::getScreenshot()
-{
-#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,
- mRect.w, mRect.h, 24, rmask, gmask, bmask, amask);
-
- if (screenshot)
- SDL_BlitSurface(mSurface, nullptr, screenshot, nullptr);
-
- return screenshot;
-}
-
void SDL2SoftwareGraphics::calcWindow(ImageCollection *const vertCol,
const int x, const int y,
const int w, const int h,
diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp
index 771d000d8..66a954927 100644
--- a/src/render/sdlgraphics.cpp
+++ b/src/render/sdlgraphics.cpp
@@ -789,28 +789,6 @@ void SDLGraphics::updateScreen()
BLOCK_END("Graphics::updateScreen")
}
-SDL_Surface *SDLGraphics::getScreenshot()
-{
-#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,
- mRect.w, mRect.h, 24, rmask, gmask, bmask, amask);
-
- if (screenshot)
- SDL_BlitSurface(mWindow, nullptr, screenshot, nullptr);
-
- return screenshot;
-}
-
void SDLGraphics::calcWindow(ImageCollection *const vertCol,
const int x, const int y,
const int w, const int h,
diff --git a/src/render/surfacegraphics.h b/src/render/surfacegraphics.h
index c8f5d3880..1de7cbc71 100644
--- a/src/render/surfacegraphics.h
+++ b/src/render/surfacegraphics.h
@@ -131,9 +131,6 @@ class SurfaceGraphics final : public Graphics
void updateScreen() override final
{ }
- SDL_Surface *getScreenshot() override final A_WARN_UNUSED
- { return nullptr; }
-
void drawNet(const int x1 A_UNUSED,
const int y1 A_UNUSED,
const int x2 A_UNUSED,
diff --git a/src/resources/openglscreenshothelper.cpp b/src/resources/openglscreenshothelper.cpp
index ec561476e..9d0edd80e 100644
--- a/src/resources/openglscreenshothelper.cpp
+++ b/src/resources/openglscreenshothelper.cpp
@@ -44,18 +44,18 @@ OpenGLScreenshotHelper::~OpenGLScreenshotHelper()
{
}
-void OpenGLScreenshotHelper::prepare(const int width,
- const int height)
+void OpenGLScreenshotHelper::prepare()
{
if (config.getBoolValue("usefbo"))
- graphicsManager.createFBO(width, height, &mFbo);
+ graphicsManager.createFBO(mainGraphics->mWidth,
+ mainGraphics->mHeight,
+ &mFbo);
}
-SDL_Surface *OpenGLScreenshotHelper::getScreenshot(const int width,
- const int height)
+SDL_Surface *OpenGLScreenshotHelper::getScreenshot()
{
- const int h = height;
- const int w = width - (width % 4);
+ const int h = mainGraphics->mHeight;
+ const int w = mainGraphics->mWidth - (mainGraphics->mWidth % 4);
GLint pack = 1;
SDL_Surface *const screenshot = MSDL_CreateRGBSurface(
diff --git a/src/resources/openglscreenshothelper.h b/src/resources/openglscreenshothelper.h
index fe9a7cfeb..ef4501cde 100644
--- a/src/resources/openglscreenshothelper.h
+++ b/src/resources/openglscreenshothelper.h
@@ -20,8 +20,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef RESOURCES_SDL2IMAGEHELPER_H
-#define RESOURCES_SDL2IMAGEHELPER_H
+#ifndef RESOURCES_OPENGLSCREENSHOTHELPER_H
+#define RESOURCES_OPENGLSCREENSHOTHELPER_H
#ifdef USE_OPENGL
@@ -40,15 +40,13 @@ class OpenGLScreenshotHelper final : public ScreenshotHelper
~OpenGLScreenshotHelper();
- void prepare(const int width,
- const int height) override final;
+ void prepare() override final;
- SDL_Surface *getScreenshot(const int width,
- const int height) override final;
+ SDL_Surface *getScreenshot() override final;
private:
FBOInfo mFbo;
};
#endif // USE_OPENGL
-#endif // RESOURCES_SDL2IMAGEHELPER_H
+#endif // RESOURCES_OPENGLSCREENSHOTHELPER_H
diff --git a/src/resources/screenshothelper.h b/src/resources/screenshothelper.h
index bde76c15a..5c5545387 100644
--- a/src/resources/screenshothelper.h
+++ b/src/resources/screenshothelper.h
@@ -38,11 +38,11 @@ class ScreenshotHelper notfinal
virtual ~ScreenshotHelper()
{ }
- virtual void prepare(const int width,
- const int height) = 0;
+ virtual void prepare() = 0;
- virtual SDL_Surface *getScreenshot(const int width,
- const int height) = 0;
+ virtual SDL_Surface *getScreenshot() = 0;
};
+extern ScreenshotHelper *screenshortHelper;
+
#endif // RESOURCES_SCREENSHOTHELPER_H
diff --git a/src/resources/sdlscreenshothelper.cpp b/src/resources/sdlscreenshothelper.cpp
index f194f93ed..eff32e303 100644
--- a/src/resources/sdlscreenshothelper.cpp
+++ b/src/resources/sdlscreenshothelper.cpp
@@ -39,14 +39,15 @@ SdlScreenshotHelper::~SdlScreenshotHelper()
{
}
-void SdlScreenshotHelper::prepare(const int width A_UNUSED,
- const int height A_UNUSED)
+void SdlScreenshotHelper::prepare()
{
}
-SDL_Surface *SdlScreenshotHelper::getScreenshot(const int width,
- const int height)
+SDL_Surface *SdlScreenshotHelper::getScreenshot()
{
+ if (!mainGraphics)
+ return nullptr;
+
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int rmask = 0xff000000;
const int gmask = 0x00ff0000;
@@ -59,7 +60,7 @@ SDL_Surface *SdlScreenshotHelper::getScreenshot(const int width,
const int amask = 0x00000000;
SDL_Surface *const screenshot = MSDL_CreateRGBSurface(SDL_SWSURFACE,
- width, height,
+ mainGraphics->mWidth, mainGraphics->mHeight,
24,
rmask, gmask, bmask, amask);
diff --git a/src/resources/sdlscreenshothelper.h b/src/resources/sdlscreenshothelper.h
index 2f873937d..ff0989cd6 100644
--- a/src/resources/sdlscreenshothelper.h
+++ b/src/resources/sdlscreenshothelper.h
@@ -20,8 +20,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef RESOURCES_SDL2IMAGEHELPER_H
-#define RESOURCES_SDL2IMAGEHELPER_H
+#ifndef RESOURCES_SDLSCREENSHOTHELPER_H
+#define RESOURCES_SDLSCREENSHOTHELPER_H
#include "resources/screenshothelper.h"
@@ -36,11 +36,9 @@ class SdlScreenshotHelper final : public ScreenshotHelper
~SdlScreenshotHelper();
- void prepare(const int width,
- const int height) override final;
+ void prepare() override final;
- SDL_Surface *getScreenshot(const int width,
- const int height) override final;
+ SDL_Surface *getScreenshot() override final;
};
-#endif // RESOURCES_SDL2IMAGEHELPER_H
+#endif // RESOURCES_SDLSCREENSHOTHELPER_H
diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp
index ca47f1b29..7f8dc0d2a 100644
--- a/src/test/testlauncher.cpp
+++ b/src/test/testlauncher.cpp
@@ -43,6 +43,7 @@
#include "resources/imagewriter.h"
#include "resources/mstack.h"
#include "resources/openglimagehelper.h"
+#include "resources/screenshothelper.h"
#include "resources/surfaceimagehelper.h"
#include "resources/wallpaper.h"
@@ -337,7 +338,7 @@ int TestLauncher::testTextures()
mainGraphics->updateScreen();
mainGraphics->drawImage(subImage, 0, 0);
delete subImage;
- SDL_Surface *const screen1 = mainGraphics->getScreenshot();
+ SDL_Surface *const screen1 = screenshortHelper->getScreenshot();
SDL_Surface *const screen2 = imageHelper->convertTo32Bit(screen1);
SDL_FreeSurface(screen1);
if (!screen2)