summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_font_main.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-13 05:13:00 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-01-13 05:15:32 +0900
commit86a97efeea946a760ed1fd0fb3ca4cc57bc81d3d (patch)
tree5b31f95b12083b653c7c8fa90c58c1b5c8d76f15 /src/lib/evas/common/evas_font_main.c
parentf21b0ee6c383b9de2723d68a5a51f071624cd29d (diff)
evas - fonts - move to using 4bit and rel 4 bit compressed font glyphs
this changes the internal encoding of font glyphs in evas to use 4bit uncompressed if small, or 4bit rle (run length encoded) if larger. this caves at least 50% of memory on fonts - and more if bigger. with large fonts (40-80pixel size) we can save in the region of 80% of memory used for glyphs. this also happesn to allow speedups in rendering too.
Diffstat (limited to '')
-rw-r--r--src/lib/evas/common/evas_font_main.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/lib/evas/common/evas_font_main.c b/src/lib/evas/common/evas_font_main.c
index 8bc9e68243..064007ffaf 100644
--- a/src/lib/evas/common/evas_font_main.c
+++ b/src/lib/evas/common/evas_font_main.c
@@ -15,6 +15,7 @@
15 15
16#include FT_OUTLINE_H 16#include FT_OUTLINE_H
17#include FT_SYNTHESIS_H 17#include FT_SYNTHESIS_H
18#include FT_BITMAP_H
18 19
19FT_Library evas_ft_lib = 0; 20FT_Library evas_ft_lib = 0;
20static int initialised = 0; 21static int initialised = 0;
@@ -352,10 +353,17 @@ _glyph_free(RGBA_Font_Glyph *fg)
352{ 353{
353 if ((!fg) || (fg == (void *)(-1))) return; 354 if ((!fg) || (fg == (void *)(-1))) return;
354 355
356 if (fg->glyph_out)
357 {
358 if ((fg->glyph_out->rle) && (fg->glyph_out->bitmap.rle_alloc))
359 free(fg->glyph_out->rle);
360 fg->glyph_out->rle = NULL;
361 if (!fg->glyph_out->bitmap.no_free_glout) free(fg->glyph_out);
362 fg->glyph_out = NULL;
363 }
355 FT_Done_Glyph(fg->glyph); 364 FT_Done_Glyph(fg->glyph);
356 /* extension calls */ 365 /* extension calls */
357 if (fg->ext_dat_free) fg->ext_dat_free(fg->ext_dat); 366 if (fg->ext_dat_free) fg->ext_dat_free(fg->ext_dat);
358 if (fg->glyph_out_free) fg->glyph_out_free(fg->glyph_out);
359 free(fg); 367 free(fg);
360} 368}
361 369
@@ -578,23 +586,32 @@ evas_common_font_int_cache_glyph_render(RGBA_Font_Glyph *fg)
578 586
579 fbg = (FT_BitmapGlyph)fg->glyph; 587 fbg = (FT_BitmapGlyph)fg->glyph;
580 588
581 fg->glyph_out = malloc(sizeof(RGBA_Font_Glyph_Out)); 589 fg->glyph_out = calloc(1, sizeof(RGBA_Font_Glyph_Out));
582 fg->glyph_out->bitmap.rows = fbg->bitmap.rows; 590 fg->glyph_out->bitmap.rows = fbg->bitmap.rows;
583 fg->glyph_out->bitmap.width = fbg->bitmap.width; 591 fg->glyph_out->bitmap.width = fbg->bitmap.width;
584 fg->glyph_out->bitmap.pitch = fbg->bitmap.pitch; 592 fg->glyph_out->bitmap.pitch = fbg->bitmap.pitch;
585 fg->glyph_out->bitmap.buffer = fbg->bitmap.buffer; 593 fg->glyph_out->bitmap.buffer = fbg->bitmap.buffer;
586 fg->glyph_out->bitmap.num_grays = fbg->bitmap.num_grays; 594 fg->glyph_out->bitmap.rle_alloc = EINA_TRUE;
587 fg->glyph_out->bitmap.pixel_mode = fbg->bitmap.pixel_mode; 595
588 596 /* This '+ 100' is just an estimation of how much memory freetype will use
589 fg->glyph_out_free = free;
590 /* This '+ 200' is just an estimation of how much memory freetype will use
591 * on it's size. This value is not really used anywhere in code - it's 597 * on it's size. This value is not really used anywhere in code - it's
592 * only for statistics. */ 598 * only for statistics. */
593 size = sizeof(RGBA_Font_Glyph) + sizeof(Eina_List) + 599 size = sizeof(RGBA_Font_Glyph) + sizeof(Eina_List) +
594 (fg->glyph_out->bitmap.width * fg->glyph_out->bitmap.rows) + 200; 600 (fg->glyph_out->bitmap.width * fg->glyph_out->bitmap.rows / 2) + 100;
595 fi->usage += size; 601 fi->usage += size;
596 if (fi->inuse) evas_common_font_int_use_increase(size); 602 if (fi->inuse) evas_common_font_int_use_increase(size);
597 603
604 fg->glyph_out->rle = evas_common_font_glyph_compress
605 (fbg->bitmap.buffer, fbg->bitmap.num_grays, fbg->bitmap.pixel_mode,
606 fbg->bitmap.pitch, fbg->bitmap.width, fbg->bitmap.rows,
607 &(fg->glyph_out->rle_size));
608
609 fg->glyph_out->bitmap.buffer = NULL;
610
611 // this may be technically incorrect as we go and free a bitmap buffer
612 // behind the ftglyph's back...
613 FT_Bitmap_Done(evas_ft_lib, &(fbg->bitmap));
614
598 return EINA_TRUE; 615 return EINA_TRUE;
599} 616}
600 617