openMSX
SDLOffScreenSurface.cc
Go to the documentation of this file.
1 #include "SDLOffScreenSurface.hh"
2 #include "SDLVisibleSurface.hh"
3 #include <cstring>
4 
5 namespace openmsx {
6 
7 SDLOffScreenSurface::SDLOffScreenSurface(const SDL_Surface& proto)
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 
38 void SDLOffScreenSurface::saveScreenshot(const std::string& filename)
39 {
41 }
42 
43 void SDLOffScreenSurface::clearScreen()
44 {
45  memset(surface->pixels, 0, uint32_t(surface->pitch) * surface->h);
46 }
47 
48 } // namespace openmsx
openmsx::SDLVisibleSurface::saveScreenshotSDL
static void saveScreenshotSDL(const SDLOutputSurface &output, const std::string &filename)
Definition: SDLVisibleSurface.cc:115
openmsx::OutputSurface::calculateViewPort
void calculateViewPort(gl::ivec2 logSize, gl::ivec2 physSize)
Definition: OutputSurface.cc:6
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
openmsx::SDLOffScreenSurface::SDLOffScreenSurface
SDLOffScreenSurface(const SDL_Surface &prototype)
Definition: SDLOffScreenSurface.cc:7
openmsx::PixelFormat::getGmask
unsigned getGmask() const
Definition: PixelFormat.hh:26
openmsx::PixelFormat
Definition: PixelFormat.hh:9
gl::vecN
Definition: gl_vec.hh:36
openmsx::OutputSurface::getPixelFormat
const PixelFormat & getPixelFormat() const
Definition: OutputSurface.hh:37
openmsx::PixelFormat::getRmask
unsigned getRmask() const
Definition: PixelFormat.hh:25
openmsx::PixelFormat::getBmask
unsigned getBmask() const
Definition: PixelFormat.hh:27
openmsx::PixelFormat::getBytesPerPixel
unsigned getBytesPerPixel() const
Definition: PixelFormat.hh:23
SDLVisibleSurface.hh
openmsx::MemBuffer::resize
void resize(size_t size)
Grow or shrink the memory block.
Definition: MemBuffer.hh:120
openmsx::PixelFormat::getAmask
unsigned getAmask() const
Definition: PixelFormat.hh:28
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::SDLOutputSurface::setSDLRenderer
void setSDLRenderer(SDL_Renderer *r)
Definition: SDLOutputSurface.hh:69
openmsx::SDLOutputSurface::setSDLPixelFormat
void setSDLPixelFormat(const SDL_PixelFormat &format)
Definition: SDLOutputSurface.cc:24
openmsx::PixelFormat::getBpp
unsigned getBpp() const
Definition: PixelFormat.hh:22
SDLSurfacePtr::get
SDL_Surface * get()
Definition: SDLSurfacePtr.hh:77
openmsx::SDLOutputSurface::setSDLSurface
void setSDLSurface(SDL_Surface *surface_)
Definition: SDLOutputSurface.hh:68
openmsx::MemBuffer::data
const T * data() const
Returns pointer to the start of the memory buffer.
Definition: MemBuffer.hh:90
SDLSurfacePtr::reset
void reset(SDL_Surface *surface_=nullptr)
Definition: SDLSurfacePtr.hh:71
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
SDLOffScreenSurface.hh