summaryrefslogtreecommitdiffstats
path: root/noatun-plugins/nexscope/bitmappool.cpp
blob: 45f35d0b1c545d34ae637626358ff27643009f9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "nex.h"

struct BitmapPool::PoolItem
{
	PoolItem() : used(false) {}
	
	bool used;
	Bitmap bitmap;
};

BitmapPool::BitmapPool()
{

}

BitmapPool::~BitmapPool()
{

}
	
Bitmap *BitmapPool::get(bool clear)
{
	mMutex.lock();
	BitmapPool::PoolItem *p=0;
	for (TQPtrListIterator<BitmapPool::PoolItem> i(mBitmaps); i.current(); ++i)
	{
		if (!(*i)->used)
			p=*i;
	}
	if (!p)
	{
		p=new BitmapPool::PoolItem;
		p->bitmap.resize(width, height);
	}
	
	p->used=true;
	
	if (clear) p->bitmap.clear();
	
	mMutex.unlock();
	return &(p->bitmap);
}

void BitmapPool::release(Bitmap *bitmap)
{
	mMutex.lock();
	for (TQPtrListIterator<BitmapPool::PoolItem> i(mBitmaps); i.current(); ++i)
	{
		if (&((*i)->bitmap)==bitmap)
			(*i)->used=false;
	}
	mMutex.unlock();
}