openMSX
Public Member Functions | List of all members
SDLSurfacePtr Class Reference

Wrapper around a SDL_Surface. More...

#include <SDLSurfacePtr.hh>

Public Member Functions

 SDLSurfacePtr (unsigned width, unsigned height, unsigned depth, Uint32 rMask, Uint32 gMask, Uint32 bMask, Uint32 aMask)
 Create a (software) surface with uninitialized pixel content.
 
 SDLSurfacePtr (SDL_Surface *surface_=nullptr)
 
 SDLSurfacePtr (SDLSurfacePtr &&other) noexcept
 
 SDLSurfacePtr (const SDLSurfacePtr &)=delete
 
SDLSurfacePtroperator= (const SDLSurfacePtr &)=delete
 
 ~SDLSurfacePtr ()
 
void reset (SDL_Surface *surface_=nullptr)
 
SDL_Surface * get ()
 
const SDL_Surface * get () const
 
void swap (SDLSurfacePtr &other) noexcept
 
SDLSurfacePtroperator= (SDLSurfacePtr &&other) noexcept
 
SDL_Surface & operator* ()
 
const SDL_Surface & operator* () const
 
SDL_Surface * operator-> ()
 
const SDL_Surface * operator-> () const
 
 operator bool () const
 
void * getLinePtr (unsigned y)
 
const void * getLinePtr (unsigned y) const
 

Detailed Description

Wrapper around a SDL_Surface.

Makes sure SDL_FreeSurface() is called when this object goes out of scope. It's modeled after std::unique_ptr, so it has the usual get(), reset() and release() methods. Like unique_ptr it can be moved but not copied.

In addition to the SDL_Surface pointer, this wrapper also (optionally) manages an extra memory buffer. Normally SDL_CreateRGBSurface() will allocate/free an internal memory buffer for the surface. On construction of the surface this buffer will be zero-initialized. Though in many cases the surface will immediately be overwritten (so zero-initialization is only extra overhead). It's possible to avoid this by creating the surface using SDL_CreateRGBSurfaceFrom(). Though the downside of this is that you have to manage the lifetime of the memory buffer yourself. And that's exactly what this wrapper can do.

As a bonus this wrapper has a getLinePtr() method to hide some of the casting. But apart from this it doesn't try to abstract any SDL functionality.

Definition at line 34 of file SDLSurfacePtr.hh.

Constructor & Destructor Documentation

◆ SDLSurfacePtr() [1/4]

SDLSurfacePtr::SDLSurfacePtr ( unsigned  width,
unsigned  height,
unsigned  depth,
Uint32  rMask,
Uint32  gMask,
Uint32  bMask,
Uint32  aMask 
)
inline

Create a (software) surface with uninitialized pixel content.

throws: bad_alloc (no need to check for nullptr).

Definition at line 39 of file SDLSurfacePtr.hh.

References openmsx::MemBuffer< T, ALIGNMENT >::data(), and openmsx::MemBuffer< T, ALIGNMENT >::resize().

◆ SDLSurfacePtr() [2/4]

SDLSurfacePtr::SDLSurfacePtr ( SDL_Surface *  surface_ = nullptr)
inlineexplicit

Definition at line 54 of file SDLSurfacePtr.hh.

◆ SDLSurfacePtr() [3/4]

SDLSurfacePtr::SDLSurfacePtr ( SDLSurfacePtr &&  other)
inlinenoexcept

Definition at line 59 of file SDLSurfacePtr.hh.

◆ SDLSurfacePtr() [4/4]

SDLSurfacePtr::SDLSurfacePtr ( const SDLSurfacePtr )
delete

◆ ~SDLSurfacePtr()

SDLSurfacePtr::~SDLSurfacePtr ( )
inline

Definition at line 69 of file SDLSurfacePtr.hh.

Member Function Documentation

◆ get() [1/2]

SDL_Surface * SDLSurfacePtr::get ( )
inline

◆ get() [2/2]

const SDL_Surface * SDLSurfacePtr::get ( ) const
inline

Definition at line 84 of file SDLSurfacePtr.hh.

◆ getLinePtr() [1/2]

void * SDLSurfacePtr::getLinePtr ( unsigned  y)
inline

Definition at line 125 of file SDLSurfacePtr.hh.

Referenced by getLinePtr(), openmsx::PNG::load(), and openmsx::PNG::saveRGBA().

◆ getLinePtr() [2/2]

const void * SDLSurfacePtr::getLinePtr ( unsigned  y) const
inline

Definition at line 130 of file SDLSurfacePtr.hh.

References getLinePtr().

◆ operator bool()

SDLSurfacePtr::operator bool ( ) const
inlineexplicit

Definition at line 120 of file SDLSurfacePtr.hh.

References get().

◆ operator*() [1/2]

SDL_Surface & SDLSurfacePtr::operator* ( )
inline

Definition at line 102 of file SDLSurfacePtr.hh.

◆ operator*() [2/2]

const SDL_Surface & SDLSurfacePtr::operator* ( ) const
inline

Definition at line 106 of file SDLSurfacePtr.hh.

◆ operator->() [1/2]

SDL_Surface * SDLSurfacePtr::operator-> ( )
inline

Definition at line 111 of file SDLSurfacePtr.hh.

◆ operator->() [2/2]

const SDL_Surface * SDLSurfacePtr::operator-> ( ) const
inline

Definition at line 115 of file SDLSurfacePtr.hh.

◆ operator=() [1/2]

SDLSurfacePtr & SDLSurfacePtr::operator= ( const SDLSurfacePtr )
delete

◆ operator=() [2/2]

SDLSurfacePtr & SDLSurfacePtr::operator= ( SDLSurfacePtr &&  other)
inlinenoexcept

Definition at line 95 of file SDLSurfacePtr.hh.

◆ reset()

void SDLSurfacePtr::reset ( SDL_Surface *  surface_ = nullptr)
inline

Definition at line 74 of file SDLSurfacePtr.hh.

References swap().

◆ swap()

void SDLSurfacePtr::swap ( SDLSurfacePtr other)
inlinenoexcept

Definition at line 89 of file SDLSurfacePtr.hh.

Referenced by reset().


The documentation for this class was generated from the following file: