Beatmup
Beatmup::BitmapFromChunk Class Reference

Loads a bitmap content from chunk. More...

#include <bitmap_from_chunk.h>

Inheritance diagram for Beatmup::BitmapFromChunk:
Beatmup::AbstractTask Beatmup::BitmapContentLock Beatmup::Object

Public Member Functions

 BitmapFromChunk ()
 
 BitmapFromChunk (AbstractBitmap &bitmap, ChunkCollection &collection, const std::string &chunkId)
 
void setBitmap (AbstractBitmap *bitmap)
 
void setCollection (ChunkCollection *collection)
 
void setChunkId (const std::string &chunkId)
 
- Public Member Functions inherited from Beatmup::AbstractTask
virtual bool processOnGPU (GraphicPipeline &gpu, TaskThread &thread)
 Executes the task on GPU. More...
 
virtual TaskDeviceRequirement getUsedDevices () const
 Communicates devices (CPU and/or GPU) the task is run on. More...
 
virtual ThreadIndex getMaxThreads () const
 Gives the upper limint on the number of threads the task may be performed by. More...
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 
- Public Member Functions inherited from Beatmup::BitmapContentLock
 BitmapContentLock ()
 
 ~BitmapContentLock ()
 
void readLock (GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
 Locks content of a bitmap for reading using a specific processing target device. More...
 
void writeLock (GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
 Locks content of a bitmap for writing using a specific processing target device. More...
 
void unlock (AbstractBitmap *bitmap)
 Drops a lock to the bitmap. More...
 
void unlockAll ()
 Unlocks all the locked bitmaps unconditionally. More...
 
template<const ProcessingTarget target>
void lock (GraphicPipeline *gpu, AbstractBitmap *input, AbstractBitmap *output)
 
void lock (GraphicPipeline *gpu, ProcessingTarget target, AbstractBitmap *input, AbstractBitmap *output)
 
template<const ProcessingTarget target>
void lock (GraphicPipeline *gpu, std::initializer_list< AbstractBitmap * > read, std::initializer_list< AbstractBitmap * > write)
 
template<typename ... Args>
void unlock (AbstractBitmap *first, Args ... others)
 

Static Public Member Functions

static void load (AbstractBitmap &bitmap, ChunkCollection &collection, const std::string &chunkId)
 Loads a bitmap content from a given collection and chunk. More...
 
- Static Public Member Functions inherited from Beatmup::AbstractTask
static ThreadIndex validThreadCount (int number)
 Valid thread count from a given integer value. More...
 

Private Member Functions

virtual bool process (TaskThread &thread)
 Executes the task on CPU within a given thread. More...
 
virtual void beforeProcessing (ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu)
 Instruction called before the task is executed. More...
 
virtual void afterProcessing (ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted)
 Instruction called after the task is executed. More...
 

Private Attributes

AbstractBitmapbitmap
 
ChunkCollectioncollection
 
std::string chunkId
 

Additional Inherited Members

- Public Types inherited from Beatmup::AbstractTask
enum class  TaskDeviceRequirement { CPU_ONLY , GPU_OR_CPU , GPU_ONLY }
 Specifies which device (CPU and/or GPU) is used to run the task. More...
 

Detailed Description

Loads a bitmap content from chunk.

The bitmap needs to be created in advance. The loaded chunk contains pixel data in binary form.

Definition at line 31 of file bitmap_from_chunk.h.

Constructor & Destructor Documentation

◆ BitmapFromChunk() [1/2]

Beatmup::BitmapFromChunk::BitmapFromChunk ( )
inline

Definition at line 40 of file bitmap_from_chunk.h.

40 : bitmap(nullptr), collection(nullptr) {}
ChunkCollection * collection

◆ BitmapFromChunk() [2/2]

Beatmup::BitmapFromChunk::BitmapFromChunk ( AbstractBitmap bitmap,
ChunkCollection collection,
const std::string &  chunkId 
)
inline

Definition at line 41 of file bitmap_from_chunk.h.

Member Function Documentation

◆ process()

bool BitmapFromChunk::process ( TaskThread thread)
privatevirtual

Executes the task on CPU within a given thread.

Generally called by multiple threads.

Parameters
threadassociated task execution context
Returns
true if the execution is finished correctly, false otherwise

Implements Beatmup::AbstractTask.

Definition at line 23 of file bitmap_from_chunk.cpp.

23  {
25  return true;
26 }
virtual const pixbyte * getData(int x, int y) const =0
Returns a pointer to given pixel.
virtual const msize getMemorySize() const =0
Bitmap size in bytes.
virtual chunksize_t fetch(const std::string &id, void *data, const chunksize_t limit)=0
Reads a chunk.

◆ beforeProcessing()

void BitmapFromChunk::beforeProcessing ( ThreadIndex  threadCount,
ProcessingTarget  target,
GraphicPipeline gpu 
)
privatevirtual

Instruction called before the task is executed.

Parameters
threadCountNumber of threads used to perform the task
targetDevice used to perform the task
gpuA graphic pipeline instance; may be null.

Reimplemented from Beatmup::AbstractTask.

Definition at line 29 of file bitmap_from_chunk.cpp.

29  {
30  NullTaskInput::check(bitmap, "bitmap");
31  NullTaskInput::check(collection, "chunk collection");
33  const size_t chunkSize = collection->chunkSize(chunkId);
34  const size_t bitmapSize = bitmap->getMemorySize();
35  InvalidArgument::check(chunkSize == bitmapSize,
36  "Chunk size does not match bitmap size: " + std::to_string(chunkSize) + " vs " + std::to_string(bitmapSize) + " bytes");
38 }
void writeLock(GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
Locks content of a bitmap for writing using a specific processing target device.
virtual bool chunkExists(const std::string &id) const =0
Check if a specific chunk exists.
virtual chunksize_t chunkSize(const std::string &id) const =0
Retrieves size of a specific chunk.
static void check(const bool condition, const std::string &message)
Definition: exception.h:75
static void check(const void *pointer, const char *which)
Definition: exception.h:115
std::string to_string(Beatmup::NNets::ActivationFunction function)

◆ afterProcessing()

void BitmapFromChunk::afterProcessing ( ThreadIndex  threadCount,
GraphicPipeline gpu,
bool  aborted 
)
privatevirtual

Instruction called after the task is executed.

Parameters
threadCountNumber of threads used to perform the task
gpuGPU to be used to execute the task; may be null.
abortedtrue if the task was aborted

Reimplemented from Beatmup::AbstractTask.

Definition at line 41 of file bitmap_from_chunk.cpp.

41  {
42  unlock(bitmap);
43 }
void unlock(AbstractBitmap *bitmap)
Drops a lock to the bitmap.

◆ setBitmap()

void Beatmup::BitmapFromChunk::setBitmap ( AbstractBitmap bitmap)
inline

Definition at line 44 of file bitmap_from_chunk.h.

44 { this->bitmap = bitmap; }

◆ setCollection()

void Beatmup::BitmapFromChunk::setCollection ( ChunkCollection collection)
inline

Definition at line 46 of file bitmap_from_chunk.h.

46 { this->collection = collection; }

◆ setChunkId()

void Beatmup::BitmapFromChunk::setChunkId ( const std::string &  chunkId)
inline

Definition at line 48 of file bitmap_from_chunk.h.

48 { this->chunkId = chunkId; }

◆ load()

void BitmapFromChunk::load ( AbstractBitmap bitmap,
ChunkCollection collection,
const std::string &  chunkId 
)
static

Loads a bitmap content from a given collection and chunk.

Launches a task in the main thread pool of the bitmap context.

Parameters
[in,out]bitmapThe bitmap to load
[in,out]collectionThe collection to load from
[in,out]chunkIdChunk ID containing the content to load

Definition at line 46 of file bitmap_from_chunk.cpp.

46  {
49 }
Context & getContext() const
Loads a bitmap content from chunk.
float performTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Performs a given task.
Definition: context.cpp:240
Beatmup::NNets::InferenceTask * task

Member Data Documentation

◆ bitmap

AbstractBitmap* Beatmup::BitmapFromChunk::bitmap
private

Definition at line 36 of file bitmap_from_chunk.h.

◆ collection

ChunkCollection* Beatmup::BitmapFromChunk::collection
private

Definition at line 37 of file bitmap_from_chunk.h.

◆ chunkId

std::string Beatmup::BitmapFromChunk::chunkId
private

Definition at line 38 of file bitmap_from_chunk.h.


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