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

Wrapper around a SDL_Surface. More...

#include <SDLSurfacePtr.hh>

Public Member Functions

 SDLSurfacePtr (const SDLSurfacePtr &)=delete
 
SDLSurfacePtroperator= (const SDLSurfacePtr &)=delete
 
 SDLSurfacePtr (unsigned width, unsigned height, unsigned depth, Uint32 rMask, Uint32 gMask, Uint32 bMask, Uint32 aMask)
 Create a (software) surface with uninitialized pixel content. More...
 
 SDLSurfacePtr (SDL_Surface *surface_=nullptr)
 
 SDLSurfacePtr (SDLSurfacePtr &&other) noexcept
 
 ~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 33 of file SDLSurfacePtr.hh.

Constructor & Destructor Documentation

◆ SDLSurfacePtr() [1/4]

SDLSurfacePtr::SDLSurfacePtr ( const SDLSurfacePtr )
delete

◆ SDLSurfacePtr() [2/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 41 of file SDLSurfacePtr.hh.

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

◆ SDLSurfacePtr() [3/4]

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

Definition at line 54 of file SDLSurfacePtr.hh.

◆ SDLSurfacePtr() [4/4]

SDLSurfacePtr::SDLSurfacePtr ( SDLSurfacePtr &&  other)
inlinenoexcept

Definition at line 59 of file SDLSurfacePtr.hh.

◆ ~SDLSurfacePtr()

SDLSurfacePtr::~SDLSurfacePtr ( )
inline

Definition at line 66 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 81 of file SDLSurfacePtr.hh.

◆ getLinePtr() [1/2]

void* SDLSurfacePtr::getLinePtr ( unsigned  y)
inline

Definition at line 122 of file SDLSurfacePtr.hh.

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

◆ getLinePtr() [2/2]

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

Definition at line 127 of file SDLSurfacePtr.hh.

References getLinePtr().

◆ operator bool()

SDLSurfacePtr::operator bool ( ) const
inlineexplicit

Definition at line 117 of file SDLSurfacePtr.hh.

◆ operator*() [1/2]

SDL_Surface& SDLSurfacePtr::operator* ( )
inline

Definition at line 99 of file SDLSurfacePtr.hh.

◆ operator*() [2/2]

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

Definition at line 103 of file SDLSurfacePtr.hh.

◆ operator->() [1/2]

SDL_Surface* SDLSurfacePtr::operator-> ( )
inline

Definition at line 108 of file SDLSurfacePtr.hh.

◆ operator->() [2/2]

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

Definition at line 112 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 92 of file SDLSurfacePtr.hh.

◆ reset()

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

◆ swap()

void SDLSurfacePtr::swap ( SDLSurfacePtr other)
inlinenoexcept

Definition at line 86 of file SDLSurfacePtr.hh.

Referenced by reset().


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