Beispiel #1
0
void GLDraw::PutImage(Point p, const Image& img, const Rect& src)
{
	if(img.GetLength() == 0)
		return;

	LLOG("PutImage " << img.GetSerialId() << ' ' << p.x << ", " << p.y << ", "<< img.GetSize());
	LLOG("SysImage cache pixels " << sTextureCache.GetSize() << ", count " << sTextureCache.GetCount());
	ImageGLDataMaker m;
	m.img = img;
	ImageGLData& sd = sTextureCache.Get(m);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, sd.texture_id);
	
	glColor3f(1.0f, 1.0f, 1.0f);
	
	if(src == img.GetSize()) {
		Rect r(p, img.GetSize());
		glBegin(GL_TRIANGLE_STRIP);
			glTexCoord2f(0, 0);
			glVertex2i(r.left, r.top);
			glTexCoord2f(1, 0);
			glVertex2i(r.right, r.top);
			glTexCoord2f(0, 1);
			glVertex2i(r.left, r.bottom);
			glTexCoord2f(1, 1);
			glVertex2i(r.right, r.bottom);
		glEnd();
	}
	else {
		Sizef iszf = img.GetSize();
		Rect s = src & img.GetSize();
		Rect r(p, s.GetSize());
		Rectf h;
		h.left = (double)s.left / iszf.cx;
		h.right = (double)s.right / iszf.cx;
		h.top = (double)s.top / iszf.cy;
		h.bottom = (double)s.bottom / iszf.cy;
		glBegin(GL_TRIANGLE_STRIP);
			glTexCoord2f(h.left, h.top);
			glVertex2i(r.left, r.top);
			glTexCoord2f(h.right, h.top);
			glVertex2i(r.right, r.top);
			glTexCoord2f(h.left, h.bottom);
			glVertex2i(r.left, r.bottom);
			glTexCoord2f(h.right, h.bottom);
			glVertex2i(r.right, r.bottom);
		glEnd();
	}

   	glDisable(GL_TEXTURE_2D);

	sTextureCache.Shrink(4 * 1024 * 768, 1000);
}
Beispiel #2
0
void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color)
{
	GuiLock __;
	if(img.GetLength() == 0)
		return;
	LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << img.GetSize());
	ImageSysDataMaker m;
	static LRUCache<ImageSysData, int64> cache;
	LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount());
	m.img = img;
	cache.Get(m).Paint(*this, x, y, src, color);
	Size sz = Ctrl::GetPrimaryScreenArea().GetSize();
	cache.Shrink(4 * sz.cx * sz.cy, 1000); // Cache must be after Paint because of PaintOnly!
}
Beispiel #3
0
void SystemDraw::SysDrawImageOp(int x, int y, const Image& img, Color color)
{
	GuiLock __;
	if(img.GetLength() == 0)
		return;
	LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << x << ", " << y << ", "<< img.GetSize());
	ImageSysDataMaker m;
	static LRUCache<ImageSysData, int64> cache;
	LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount());
	m.img = img;
	ImageSysData& sd = cache.Get(m);
	if(!IsNull(color)) {
		SetColor(color);
		cairo_mask_surface(cr, sd.surface, x, y);
	}
	else {
		cairo_set_source_surface(cr, sd.surface, x, y);
		cairo_paint(cr);
	}
	cache.Shrink(4 * 1024 * 768, 1000); // Cache must be after Paint because of PaintOnly!
}
void testLRUCache()
{
	int i;
	LRUCache c;

	int t[100];
	for (i = 0; i < 100; ++i) t[i] = 1000+i;
	char* k[100];
	for (i = 0; i < 100; ++i) {
		k[i] = new char[5];
		sprintf(k[i], "k%03d", i);
	}

	bool r;
	void* p;
	const char* k2;

	r = c.Lookup("k050", p);
	assert(!r);

	c.SetAt("k050", &t[50]);
	r = c.Lookup("k050", p);
	assert(r);
	assert(p == &t[50]);

	for (i = 0; i < 100; ++i)
		c.SetAt(k[i], &t[i]);

	r = c.getLRU(0, k2, p);
	assert(r);
	assert(strcmp(k2, "k000") == 0);
	assert(p == &t[0]);

	c.Touch("k000");
	r = c.getLRU(0, k2, p);
	assert(r);
	assert(strcmp(k2, "k001") == 0);
	assert(p == &t[1]);

	r = c.getLRU(1, k2, p);
	assert(r);
	assert(strcmp(k2, "k002") == 0);
	assert(p == &t[2]);

	c.Remove("k001");

	r = c.getLRU(0, k2, p);
	assert(r);
	assert(strcmp(k2, "k002") == 0);
	assert(p == &t[2]);

	for (i = 0; i < 98; ++i) {
		r = c.getLRU(0, k2, p);
		assert(r);
		assert(strcmp(k2, k[2+i]) == 0);
		assert(p == &t[2+i]);
		c.Remove(k2);
	}

	assert(c.GetCount() == 1);

	r = c.getLRU(0, k2, p);
	assert(r);
	assert(strcmp(k2, "k000") == 0);
	assert(p == &t[0]);

	assert(!c.getLRU(1, k2, p));
}