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 (const SDLSurfacePtr &)
SDLSurfacePtroperator= (const SDLSurfacePtr &)
 SDLSurfacePtr (SDL_Surface *surface_=nullptr, void *buffer_=nullptr)
 SDLSurfacePtr (SDLSurfacePtr &&other)
 ~SDLSurfacePtr ()
void reset (SDL_Surface *surface_=nullptr)
SDL_Surface * get ()
const SDL_Surface * get () const
void swap (SDLSurfacePtr &other)
SDLSurfacePtroperator= (SDLSurfacePtr &&other)
SDL_Surface & operator* ()
const SDL_Surface & operator* () const
SDL_Surface * operator-> ()
const SDL_Surface * operator-> () 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 30 of file SDLSurfacePtr.hh.

Constructor & Destructor Documentation

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 35 of file SDLSurfacePtr.hh.

References utf8::unchecked::size().

SDLSurfacePtr::SDLSurfacePtr ( const SDLSurfacePtr )
SDLSurfacePtr::SDLSurfacePtr ( SDL_Surface *  surface_ = nullptr,
void *  buffer_ = nullptr 
)
inlineexplicit

Definition at line 57 of file SDLSurfacePtr.hh.

SDLSurfacePtr::SDLSurfacePtr ( SDLSurfacePtr &&  other)
inline

Definition at line 64 of file SDLSurfacePtr.hh.

SDLSurfacePtr::~SDLSurfacePtr ( )
inline

Definition at line 72 of file SDLSurfacePtr.hh.

Member Function Documentation

SDL_Surface* SDLSurfacePtr::get ( )
inline
const SDL_Surface* SDLSurfacePtr::get ( ) const
inline

Definition at line 90 of file SDLSurfacePtr.hh.

void* SDLSurfacePtr::getLinePtr ( unsigned  y)
inline

Definition at line 128 of file SDLSurfacePtr.hh.

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

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

Definition at line 133 of file SDLSurfacePtr.hh.

References getLinePtr().

SDL_Surface& SDLSurfacePtr::operator* ( )
inline

Definition at line 110 of file SDLSurfacePtr.hh.

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

Definition at line 114 of file SDLSurfacePtr.hh.

SDL_Surface* SDLSurfacePtr::operator-> ( )
inline

Definition at line 119 of file SDLSurfacePtr.hh.

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

Definition at line 123 of file SDLSurfacePtr.hh.

SDLSurfacePtr& SDLSurfacePtr::operator= ( const SDLSurfacePtr )
SDLSurfacePtr& SDLSurfacePtr::operator= ( SDLSurfacePtr &&  other)
inline

Definition at line 101 of file SDLSurfacePtr.hh.

References swap().

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

Definition at line 95 of file SDLSurfacePtr.hh.

Referenced by operator=(), and reset().


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