openMSX
SDLOffScreenSurface.cc
Go to the documentation of this file.
3#include "narrow.hh"
4#include <cstring>
5
6namespace openmsx {
7
9{
10 gl::ivec2 size(proto.w, proto.h);
12 setSDLPixelFormat(*proto.format);
13
14 // SDL_CreateRGBSurface() allocates an internal buffer, on 32-bit
15 // systems this buffer is only 8-bytes aligned. For some scalers (with
16 // SSE(2) optimizations) we need a 16-byte aligned buffer. So now we
17 // allocate the buffer ourselves and create the SDL_Surface with
18 // SDL_CreateRGBSurfaceFrom().
19 // Of course it would be better to get rid of SDL_Surface in the
20 // OutputSurface interface.
21
22 const PixelFormat& frmt = getPixelFormat();
23 unsigned pitch2 = proto.w * frmt.getBytesPerPixel();
24 assert((pitch2 % 16) == 0);
25 unsigned bufSize = pitch2 * proto.h;
26 buffer.resize(bufSize);
27 ranges::fill(std::span{buffer.data(), bufSize}, 0);
28 surface.reset(SDL_CreateRGBSurfaceFrom(
29 buffer.data(), proto.w, proto.h, narrow<int>(frmt.getBpp()), narrow<int>(pitch2),
30 frmt.getRmask(), frmt.getGmask(), frmt.getBmask(), frmt.getAmask()));
31
32 setSDLSurface(surface.get());
33
34 // Used (only?) by 'screenshot -with-osd'.
35 renderer.reset(SDL_CreateSoftwareRenderer(surface.get()));
36 setSDLRenderer(renderer.get());
37}
38
39void SDLOffScreenSurface::saveScreenshot(const std::string& filename)
40{
42}
43
44void SDLOffScreenSurface::clearScreen()
45{
46 memset(surface->pixels, 0, size_t(surface->pitch) * surface->h);
47}
48
49} // 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:24
unsigned getGmask() const
Definition: PixelFormat.hh:28
unsigned getAmask() const
Definition: PixelFormat.hh:30
unsigned getBytesPerPixel() const
Definition: PixelFormat.hh:25
unsigned getRmask() const
Definition: PixelFormat.hh:27
unsigned getBmask() const
Definition: PixelFormat.hh:29
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 void fill(ForwardRange &&range, const T &value)
Definition: ranges.hh:287
size_t size(std::string_view utf8)