Files
flenser/dw/imgrenderer.hh
ADAM David Alan Martin 9dbf5ee536
Some checks failed
CI / ubuntu-latest-html-tests (push) Has been cancelled
CI / ubuntu-latest-no-tls (push) Has been cancelled
CI / ubuntu-latest-mbedtls2 (push) Has been cancelled
CI / ubuntu-latest-openssl-3 (push) Has been cancelled
CI / ubuntu-latest-with-old-std (push) Has been cancelled
CI / ubuntu-20-04-openssl-1-1 (push) Has been cancelled
CI / alpine-mbedtls-3_6_0 (push) Has been cancelled
CI / macOS-13-openssl-1-1 (push) Has been cancelled
CI / macOS-13-openssl-3 (push) Has been cancelled
CI / freebsd-14-openssl-3 (push) Has been cancelled
CI / windows-mbedtls (push) Has been cancelled
This one pushes ownership a lot wider.
2025-08-09 12:29:05 -04:00

87 lines
2.0 KiB
C++

#ifndef __DW_IMGRENDERER_HH__
#define __DW_IMGRENDERER_HH__
#include <set>
#ifndef __INCLUDED_FROM_DW_CORE_HH__
# error Do not include this file directly, use "core.hh" instead.
#endif
namespace dw {
namespace core {
/**
* \brief ...
*
* \sa \ref dw-images-and-backgrounds
*/
class ImgRenderer
{
public:
virtual ~ImgRenderer () { }
/**
* \brief Called, when an image buffer is attached.
*
* This is typically the case when all meta data (size, depth) has been read.
*/
virtual void setBuffer (core::Imgbuf *buffer, bool resize = false) = 0;
/**
* \brief Called, when data from a row is available and has been copied into
* the image buffer.
*
* The implementation will typically queue the respective area for drawing.
*/
virtual void drawRow (int row) = 0;
/**
* \brief Called, when all image data has been retrieved.
*
* The implementation may use this instead of "drawRow" for drawing, to
* limit the number of draws.
*/
virtual void finish () = 0;
/**
* \brief Called, when there are problems with the retrieval of image data.
*
* The implementation may use this to indicate an error.
*/
virtual void fatal () = 0;
};
/**
* \brief Implementation of ImgRenderer, which distributes all calls
* to a set of other implementations of ImgRenderer.
*
* The order of the call children is not defined, especially not
* identical to the order in which they have been added.
*/
class ImgRendererDist: public ImgRenderer
{
std::set< std::unique_ptr< ImgRenderer > > children;
public:
void setBuffer (core::Imgbuf *buffer, bool resize);
void drawRow (int row);
void finish ();
void fatal ();
void put (std::unique_ptr< ImgRenderer > child)
{ children.insert( std::move( child ) ); }
void
remove( ImgRenderer * child)
{
children.erase( std::find_if( begin( children ), end( children ),
[&]( const auto &elem ) { return child == elem.get(); } ) );
}
};
} // namespace core
} // namespace dw
#endif // __DW_IMGRENDERER_HH__