openMSX
SDLOffScreenSurface.cc
Go to the documentation of this file.
3#include <cstring>
4
5namespace openmsx {
6
8{
9 gl::ivec2 size(proto.w, proto.h);
11 setSDLPixelFormat(*proto.format);
12
13 // SDL_CreateRGBSurface() allocates an internal buffer, on 32-bit
14 // systems this buffer is only 8-bytes aligned. For some scalers (with
15 // SSE(2) optimizations) we need a 16-byte aligned buffer. So now we
16 // allocate the buffer ourselves and create the SDL_Surface with
17 // SDL_CreateRGBSurfaceFrom().
18 // Of course it would be better to get rid of SDL_Surface in the
19 // OutputSurface interface.
20
21 const PixelFormat& frmt = getPixelFormat();
22 unsigned pitch2 = proto.w * frmt.getBytesPerPixel();
23 assert((pitch2 % 16) == 0);
24 unsigned bufSize = pitch2 * proto.h;
25 buffer.resize(bufSize);
26 memset(buffer.data(), 0, bufSize);
27 surface.reset(SDL_CreateRGBSurfaceFrom(
28 buffer.data(), proto.w, proto.h, frmt.getBpp(), pitch2,
29 frmt.getRmask(), frmt.getGmask(), frmt.getBmask(), frmt.getAmask()));
30
31 setSDLSurface(surface.get());
32
33 // Used (only?) by 'screenshot -with-osd'.
34 renderer.reset(SDL_CreateSoftwareRenderer(surface.get()));
35 setSDLRenderer(renderer.get());
36}
37
38void SDLOffScreenSurface::saveScreenshot(const std::string& filename)
39{
41}
42
43void SDLOffScreenSurface::clearScreen()
44{
45 memset(surface->pixels, 0, uint32_t(surface->pitch) * surface->h);
46}
47
48} // namespace openmsx
void reset(SDL_Surface *surface_=nullptr)
SDL_Surface * get()
void resize(size_t size)
Grow or shrink the memory block.
Definition: MemBuffer.hh:111
const T * data() const
Returns pointer to the start of the memory buffer.
Definition: MemBuffer.hh:81
const PixelFormat & getPixelFormat() const
void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize)
Definition: OutputSurface.cc:6
unsigned getBpp() const
Definition: PixelFormat.hh:22
unsigned getGmask() const
Definition: PixelFormat.hh:26
unsigned getAmask() const
Definition: PixelFormat.hh:28
unsigned getBytesPerPixel() const
Definition: PixelFormat.hh:23
unsigned getRmask() const
Definition: PixelFormat.hh:25
unsigned getBmask() const
Definition: PixelFormat.hh:27
SDLOffScreenSurface(const SDL_Surface &prototype)
void setSDLSurface(SDL_Surface *surface_)
void setSDLPixelFormat(const SDL_PixelFormat &format)
void setSDLRenderer(SDL_Renderer *r)
static void saveScreenshotSDL(const SDLOutputSurface &output, const std::string &filename)
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename
size_t size(std::string_view utf8)