2 Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "osdopenvg.h"
26 //#include <Magick++.h>
30 #include "teletxt/txtfont.h"
32 #include <sys/syscall.h>
33 #include <fontconfig/fontconfig.h>
38 //using namespace Magick;
40 extern uint8_t vdr_data[] asm("_binary_other_vdrhires_jpg_start");
41 extern uint8_t vdr_data_end[] asm("_binary_other_vdrhires_jpg_end");
42 extern uint8_t wallpaper_data[] asm("_binary_other_wallpaper720p_jpg_start");
43 extern uint8_t wallpaper_data_end[] asm("_binary_other_wallpaper720p_jpg_end");
46 #define BACKBUFFER_WIDTH 1280
47 #define BACKBUFFER_HEIGHT 720
50 OsdOpenVG::OsdOpenVG()
54 lastrendertime=getTimeMS();
60 freetype_inited=false;
62 const char *fontname="Droid Sans:style=Regular";
63 cur_fontname=(char*)malloc(strlen(fontname)+1);
64 strcpy(cur_fontname,fontname);
68 OsdOpenVG::~OsdOpenVG()
76 if (cur_fontname) free(cur_fontname);
77 if (freetype_inited) FT_Done_Face(ft_face);
78 if (!fontnames.size()) {
79 vector<char*>::iterator itty=fontnames.begin();
80 while (itty!=fontnames.end()) {
86 if (!fontnames_keys.size()) {
87 vector<char*>::iterator itty=fontnames_keys.begin();
88 while (itty!=fontnames_keys.end()) {
101 int OsdOpenVG::init(void* device)
103 if (initted) return 0;
105 Video* video = Video::getInstance();
106 //window=*((HWND*)device);
108 // May be this device specific part should go to a device specific child class
110 //init broadcom chipset (Move to video?)
113 //First get connection to egl
114 egl_display=eglGetDisplay(EGL_DEFAULT_DISPLAY);
116 if (egl_display==EGL_NO_DISPLAY) {
117 Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x",eglGetError());
124 if (eglInitialize(egl_display, NULL, NULL)==EGL_FALSE) {
125 Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x",eglGetError());
131 const char *query_str=eglQueryString(egl_display,EGL_CLIENT_APIS);
132 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
133 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());
134 query_str=eglQueryString(egl_display,EGL_EXTENSIONS);
135 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
136 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());
138 if (eglBindAPI(EGL_OPENVG_API)==EGL_FALSE) {
139 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api failed! %x",eglGetError());
144 const EGLint attributs[]={
145 EGL_RED_SIZE,8,EGL_GREEN_SIZE, 8,EGL_BLUE_SIZE, 8,EGL_ALPHA_SIZE, 8,
146 EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT,
147 EGL_CONFORMANT, EGL_OPENVG_BIT,
149 }; // Here, we might have to select the resolution!
154 if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number)==EGL_FALSE) {
155 Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %x",eglGetError());
162 egl_context=eglCreateContext(egl_display,egl_ourconfig,NULL,NULL);
163 if (egl_context==EGL_NO_CONTEXT) {
164 Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %x",eglGetError());
169 // warning broadcom specific, get display size!
170 display_width=display_height=0;
171 if (graphics_get_display_size(0, &display_width, &display_height)<0) {
172 Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) ");
176 Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height);
177 VC_RECT_T dst_rect ={0,0,display_width,display_height};
178 VC_RECT_T src_rect={0,0,BACKBUFFER_WIDTH <<16,BACKBUFFER_HEIGHT<<16};
179 VC_RECT_T src_rect_bg={0,0,16<<16,16<<16};
180 VC_RECT_T src_rect_im={0,0,16,16};
182 uint32_t back_image_ptr;
183 bcm_backres=vc_dispmanx_resource_create(VC_IMAGE_RGBX32,16,16,&back_image_ptr);
184 unsigned int color[16*16];
185 DrawStyle bg=DrawStyle::WALLPAPER;
186 if (bg.ft!=DrawStyle::GradientLinear) {
189 //memset(color,0xFF,sizeof(unsigned int)*4*8);
190 for (int j=0;j<16;j++) {
191 int helpr=(((15-j)*bg.red)+(j*bg.grad_col[0].red))/15;
192 int helpb=(((15-j)*bg.blue)+(j*bg.grad_col[0].blue))/15;
193 int helpg=(((15-j)*bg.green)+(j*bg.grad_col[0].green))/15;
194 //unsigned int cur_col=help | (help<< 8) | (help<< 16) | (0xFF<< 24);
195 unsigned int cur_col=helpr | (helpg<< (8)) | (helpb<< (16)) | (0xFF<< (24));
196 for (int i=0;i<16;i++) {
197 color[i+16*j]=cur_col;
200 vc_dispmanx_resource_write_data(bcm_backres,VC_IMAGE_RGBX32,16*4,color,&src_rect_im);
202 DISPMANX_UPDATE_HANDLE_T bcm_update;
203 bcm_display=vc_dispmanx_display_open(0);
204 bcm_update=vc_dispmanx_update_start(0);
205 bcm_element=vc_dispmanx_element_add(bcm_update,bcm_display,
207 &src_rect,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);
210 bcm_background=vc_dispmanx_element_add(bcm_update,bcm_display,
211 0,&dst_rect,bcm_backres ,
212 &src_rect_bg,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);
214 vc_dispmanx_update_submit_sync(bcm_update);
218 static EGL_DISPMANX_WINDOW_T nativewindow;
219 nativewindow.element=bcm_element;
220 nativewindow.height=BACKBUFFER_HEIGHT;
221 nativewindow.width=BACKBUFFER_WIDTH;
223 egl_surface = eglCreateWindowSurface(egl_display,egl_ourconfig, &nativewindow,NULL );
224 if (egl_surface==EGL_NO_SURFACE) {
225 Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!");
229 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current in1%d",syscall(SYS_gettid));
230 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
231 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed");
237 query_str=(const char*)vgGetString(VG_VERSION) ;
238 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
239 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
241 query_str=(const char*)vgGetString(VG_VENDOR) ;
242 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
243 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
245 query_str=(const char*)vgGetString(VG_RENDERER) ;
246 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
247 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
249 query_str=(const char*)vgGetString(VG_EXTENSIONS) ;
250 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
251 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
253 aspect_correction= ((float)BACKBUFFER_HEIGHT)/576.f/(((float)BACKBUFFER_WIDTH)/720.f);
255 if (!fontnames.size()) {
256 //inspired by and copied from vdr's code
258 FcObjectSet *objset= FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
259 FcPattern * pattern=FcPatternCreate();
260 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
261 FcFontSet* fonts = FcFontList(NULL, pattern, objset);
262 for (int i=0; i<fonts->nfont;i++) {
263 char *s = (char *)FcNameUnparse(fonts->fonts[i]);
266 char *c= strchr(s,':');
268 char *s2= strchr(c+1,',');
271 char *p=strchr(s,',');
274 else memmove(p,c,strlen(c)+1);
276 char *key=(char*)malloc(strlen(s)+1);
278 fontnames_keys.push_back(key);
279 char *s2=strstr(s,"style=");
281 memmove(s2,s2+6,strlen(s2+6)+1);
283 fontnames.push_back(s);
286 FcFontSetDestroy(fonts);
287 FcPatternDestroy(pattern);
288 FcObjectSetDestroy(objset);
291 if (!loadFont(false)) {
294 vgttfont=vgCreateFont(0);
295 vgttpaint=vgCreatePaint();
296 vgSetParameteri( vgttpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
297 vgSetColor(vgttpaint,0xffffffff);
299 eglSwapInterval(egl_display, 1 );
301 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out 1%d",syscall(SYS_gettid));
302 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
303 //Now we will create the Screen
304 initted = 1; // must set this here or create surface won't work
307 /*if (((VideoOMX*)Video::getInstance())->initUsingOSDObjects()!=1) { //call Video for init stuff
316 #ifdef PICTURE_DECODER_OMX
317 imageomx=new ImageOMX(&reader);
318 reader.addDecoder(imageomx);
325 void OsdOpenVG::getScreenSize(int &width, int &height)
327 width=BACKBUFFER_WIDTH;
328 height=BACKBUFFER_HEIGHT;
331 void OsdOpenVG::getRealScreenSize(int &width, int &height)
334 height=display_height;
337 bool OsdOpenVG::screenShot(void *buffer, int width, int height, bool osd /*include osd*/)
339 if (!initted) return false;
340 if (!buffer) return false;
342 DISPMANX_RESOURCE_HANDLE_T res;
343 DISPMANX_DISPLAY_HANDLE_T display;
347 res=vc_dispmanx_resource_create(VC_IMAGE_RGBA32,width,height,&image_ptr);
348 display=vc_dispmanx_display_open(0);
350 vc_dispmanx_snapshot(display, res,
351 (DISPMANX_TRANSFORM_T)(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL/*|DISPMANX_SNAPSHOT_PACK*/));
355 vc_dispmanx_snapshot(display, res,
356 (DISPMANX_TRANSFORM_T)(DISPMANX_SNAPSHOT_FILL));
358 vc_dispmanx_rect_set(&rect,0,0,width,height);
359 vc_dispmanx_resource_read_data(res, &rect, buffer, width*4);
360 vc_dispmanx_resource_delete(res);
361 vc_dispmanx_display_close(display);
367 void OsdOpenVG::initPaths()
372 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
373 VG_PATH_DATATYPE_F,1.f,0.f,
374 0,0,VG_PATH_CAPABILITY_ALL);
376 vguLine(current,0.f,0.f,1.f,0.f);
378 std_paths[HorzLine]=current;
380 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
381 VG_PATH_DATATYPE_F,1.f,0.f,
382 0,0,VG_PATH_CAPABILITY_ALL);
383 vguLine(current,0.f,0.f,0.f,1.f);
385 std_paths[VertLine]=current;
387 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
388 VG_PATH_DATATYPE_F,1.f,0.f,
389 0,0,VG_PATH_CAPABILITY_ALL);
390 //vguRect(current,0.f,0.f,1.f,1.f);
391 vguRect(current,0.f,0.f,1.f,1.f);
393 std_paths[Rectangle]=current;
395 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
396 VG_PATH_DATATYPE_F,1.f,0.f,
398 vguEllipse(current,0.f,0.f,1.f,1.f);
400 std_paths[Point]=current;
404 void OsdOpenVG::destroyPaths()
406 vgDestroyPath(std_paths[HorzLine]);
407 vgDestroyPath(std_paths[VertLine]);
408 vgDestroyPath(std_paths[Rectangle]);
409 vgDestroyPath(std_paths[Point]);
413 int OsdOpenVG::stopUpdate()
420 void OsdOpenVG::purgeAllReferences()
423 styles_ref.clear(); // remove all references
426 map<void *,ImageIndex>::iterator mitty=monobitmaps.begin();
427 while (mitty!=monobitmaps.end()) {
428 vgDestroyImage((VGImage)(*mitty).second);
433 /*map<string,ImageIndex>::iterator jitty=jpegs.begin();
434 while (jitty!=jpegs.end()) {
435 vgDestroyImage((VGImage)(*jitty).second);
440 map<TVMediaInfo,ImageIndex>::iterator titty=tvmedias.begin();
441 while (titty!=tvmedias.end()) {
442 vgDestroyImage((VGImage)(*titty).second);
447 map<pair<Colour*,unsigned int>,unsigned int>::iterator sitty=styles.begin();
448 while (sitty!=styles.end()) {
449 vgDestroyPaint((VGPaint)(*sitty).second);
456 int OsdOpenVG::shutdown()
459 #ifdef PICTURE_DECODER_OMX
460 if (imageomx) reader.removeDecoder(imageomx);
464 if (!initted) return 0;
467 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1");
469 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1a");
470 //(((VideoOMX*)Video::getInstance())->shutdownUsingOSDObjects());
471 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
472 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in shutdown %x",eglGetError());
474 if (eglBindAPI(EGL_OPENVG_API)==EGL_FALSE) {
475 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api thread failed! %x",eglGetError());
478 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark2");
480 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark3");
487 //purgeAllReferences();
489 vgDestroyFont(vgfont);
490 vgDestroyFont(vgttfont);
491 vgDestroyPaint(vgttpaint);
493 float colclear[]={0.8f,0.8f,0.8f,1.f};
494 vgSetfv(VG_CLEAR_COLOR,4,colclear);
495 vgClear(0,0,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT);
496 eglSwapBuffers(egl_display, egl_surface);
497 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out final");
498 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
499 if (eglDestroySurface(egl_display,egl_surface)==EGL_FALSE) {
500 Log::getInstance()->log("OSD", Log::ERR, "eglDestroySurface failed %x",eglGetError());
502 if (eglDestroyContext(egl_display,egl_context)==EGL_FALSE) {
503 Log::getInstance()->log("OSD", Log::ERR, "eglDestroyContext failed %x",eglGetError());
505 if (eglTerminate(egl_display )==EGL_FALSE) {
506 Log::getInstance()->log("OSD", Log::ERR, "eglTerminate failed %x",eglGetError());
509 DISPMANX_UPDATE_HANDLE_T bcm_update;
510 bcm_update=vc_dispmanx_update_start(0);
512 vc_dispmanx_element_remove(bcm_update,bcm_element);
513 vc_dispmanx_element_remove(bcm_update,bcm_background);
514 vc_dispmanx_update_submit_sync(bcm_update);
515 vc_dispmanx_resource_delete(bcm_backres);
516 vc_dispmanx_display_close(bcm_display);
526 void OsdOpenVG::threadMethod()
528 // We have to claim the egl context for this thread
529 Log::getInstance()->log("OSD", Log::NOTICE, "Entering drawing thread");
530 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
531 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in thread %x",eglGetError());
534 if (eglBindAPI(EGL_OPENVG_API)==EGL_FALSE) {
535 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api thread failed! %x",eglGetError());
542 unsigned int waittime=1;
546 long long time1 = getTimeMS();
547 if ((time1 - lastrendertime) > 200) {//5 fps for OSD updates are enough, avoids tearing
549 lastrendertime = getTimeMS();
552 if (processTasks()) ts=0;
554 if (!threadIsActive()) {
555 if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT )== EGL_FALSE) {
556 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current out thread failed");
561 struct timespec target_time;
562 clock_gettime(CLOCK_REALTIME,&target_time);
563 target_time.tv_nsec+=1000000LL*ts;
564 if (target_time.tv_nsec>999999999) {
565 target_time.tv_nsec-=1000000000L;
566 target_time.tv_sec+=1;
569 threadWaitForSignalTimed(&target_time);
574 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
578 void OsdOpenVG::threadPostStopCleanup()
582 Log::getInstance()->log("OSD", Log::NOTICE, "Exiting drawing thread");
585 void OsdOpenVG::InternalRendering(){
587 Colour bg=DrawStyle::WALLPAPER;
588 float colclear[]={1.f,1.0f,1.f,1.f};
589 if (bg.alpha==0) colclear[3]=0.f;
590 vgSetfv(VG_CLEAR_COLOR,4,colclear);
591 vgClear(0,0,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT);
592 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
595 drawSurfaces(); //iterate through and draws all commands
597 //Show it to the user!
598 eglSwapBuffers(egl_display, egl_surface);
605 float OsdOpenVG::getFontHeight()
607 return font_height; //dummy
609 float OsdOpenVG::getCharWidth(wchar_t c)
611 unsigned int glyph_index=FT_Get_Char_Index(ft_face,c);
612 return font_exp_x[glyph_index];
615 unsigned int OsdOpenVG::loadTTchar(cTeletextChar c)
617 unsigned int glyph_index=c.getGlyphIndex();
618 if (tt_font_chars.find(glyph_index)!=tt_font_chars.end())
623 unsigned int buffer[10];
624 const VGfloat glyphOrigin[] = { 0.f, 0.f };
625 const VGfloat escapement[] = { 12.f, 0.f };
626 unsigned int * charmap = GetFontChar(c, buffer);
627 if (!charmap) { //invalid char
630 for (int i=0;i<10;i++) {
631 buffer[i]=charmap[i]>>4;
634 VGImage handle = vgCreateImage(
638 VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER
639 | VG_IMAGE_QUALITY_BETTER);
640 vgImageSubData(handle, buffer, 4, VG_A_1, 0, 0, 12, 10);
644 handle, (VGfloat*)glyphOrigin, (VGfloat*)escapement);
645 vgDestroyImage(handle);
646 tt_font_chars[glyph_index]=1;
651 int OsdOpenVG::getFontNames(const char *** names,const char *** names_keys)
653 *names=(const char**)&(fontnames[0]);
654 *names_keys=(const char**)&(fontnames_keys[0]);
655 return fontnames.size();
658 void OsdOpenVG::setFont(const char * fontname) {
660 if (strcmp(fontname,cur_fontname)) {
662 if (cur_fontname) free(cur_fontname);
663 cur_fontname=(char*)malloc(strlen(fontname)+1);
664 strcpy(cur_fontname,fontname);
666 struct OpenVGCommand comm;
667 comm.task=OVGreplacefont;
668 putOpenVGCommand(comm,false);
675 int OsdOpenVG::loadFont(bool newfont)
678 float font_size=16.f;
679 if (!freetype_inited) {
680 error=FT_Init_FreeType(&ft_library);
683 Log::getInstance()->log("OSD", Log::WARN, "Could not load freetype %x",error);
688 if (!freetype_inited || newfont) {
689 //first get the filename algorith extracted from vdr by Klaus Schmidinger
691 FcPattern *pattern=FcNameParse((FcChar8*)cur_fontname);
692 FcPatternAddBool(pattern,FC_SCALABLE,FcTrue);
693 FcConfigSubstitute(NULL,pattern,FcMatchPattern);
694 FcDefaultSubstitute(pattern);
696 FcFontSet *fonts=FcFontSort(NULL,pattern,FcFalse,NULL,&fres);
697 FcChar8 *filename=NULL;
699 for (int i=0;i<fonts->nfont;i++) {
701 FcPatternGetBool(fonts->fonts[i],FC_SCALABLE,0,&canscale);
703 FcPatternGetString(fonts->fonts[i],FC_FILE,0,&filename);
707 FcFontSetDestroy(fonts);
709 Log::getInstance()->log("OSD", Log::CRIT, "Could not locate a font! Abort!");
712 FcPatternDestroy(pattern);
714 Log::getInstance()->log("OSD", Log::NOTICE, "Load Font %s: %s", cur_fontname,filename);
715 // second load the font
717 error=FT_New_Face(ft_library,(const char*)filename,0,&new_ft_face );
719 Log::getInstance()->log("OSD", Log::WARN, "Could not load font face %x %s",error,filename);
722 error=FT_Set_Char_Size(new_ft_face,0,font_size*256,0,0 /*dpi*/);
724 FT_Done_Face(new_ft_face);
725 Log::getInstance()->log("OSD", Log::WARN, "Could not set face size %x",error);
728 FT_Face old_ft_face=ft_face; // do it thread safe
730 if (freetype_inited) FT_Done_Face(old_ft_face);//
731 freetype_inited=true;
733 vgfont=vgCreateFont(0);
736 font_height=ft_face->size->metrics.height/256.f;
737 cur_char = FT_Get_First_Char(ft_face,&glyph);
738 vector<VGubyte> segments;
739 vector<VGfloat> coord;
740 segments.reserve(256);
742 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph test %d %x %x %d",cur_char,font_data_end,font_data,glyph);
745 error=FT_Load_Glyph(ft_face,glyph,FT_LOAD_DEFAULT);
747 FT_Done_Face(ft_face);
748 Log::getInstance()->log("OSD", Log::WARN, "Could not load glyph %x",error);
752 FT_Outline ot=ft_face->glyph->outline;
756 if (ot.n_contours ==0) {
757 path=VG_INVALID_HANDLE;
759 path=vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
760 1.0f,0.f,0,0,VG_PATH_CAPABILITY_ALL);
763 FT_Vector *pt=ot.points;
764 const char *tags=ot.tags;
765 const short* cont=ot.contours;
766 short n_cont=ot.n_contours;
767 short n_point=ot.n_points;
769 for (short point=0;n_cont!=0;cont++,n_cont--) {
770 short next_cont=*cont+1;
773 short first_point=point;
774 //Log::getInstance()->log("OSD", Log::DEBUG, "runs %d",*cont);
775 for (;point<next_cont;point++) {
776 char tag=tags[point];
777 FT_Vector fpoint=pt[point];
778 // Log::getInstance()->log("OSD", Log::DEBUG, "tag %d point %d %d: %d %d",tag,fpoint.x,fpoint.y,point,n_point);
780 segments.push_back(VG_MOVE_TO);
782 } else if (tag &0x1) { //on curve
784 segments.push_back(VG_LINE_TO);
785 } else if (last_tag &0x2){
786 segments.push_back(VG_CUBIC_TO);
788 segments.push_back(VG_QUAD_TO);
793 if (!(last_tag &0x1)) {
794 segments.push_back(VG_QUAD_TO);
795 int coord_size=coord.size();
796 VGfloat x=(coord[coord_size-2]+ ((float)fpoint.x)/256.f)*0.5f*aspect_correction;
797 VGfloat y=(coord[coord_size-1]+(font_size- ((float)fpoint.y)/256.f))*0.5f;
806 coord.push_back(((float)fpoint.x)*aspect_correction/256.);
807 coord.push_back(font_size-((float)fpoint.y)/256.);
808 //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph coord %d %d %g %g",fpoint.x,fpoint.y,coord[coord.size()-2],coord[coord.size()-1]);
810 if (!(last_tag &0x1)) {
812 segments.push_back(VG_CUBIC_TO);
814 segments.push_back(VG_QUAD_TO);
816 coord.push_back(((float)pt[first_point].x)*aspect_correction/256.);
817 coord.push_back(font_size-((float)pt[first_point].y)/256.);
819 //segments.push_back(VG_CLOSE_PATH);
823 vgAppendPathData(path,segments.size(),&segments[0],&coord[0]);
825 /* for (int m=0;m<segments.size();m++) {
829 Log::getInstance()->log("OSD", Log::DEBUG, "Move To %g %g",coord[n],coord[n+1]);n+=2; break;
831 Log::getInstance()->log("OSD", Log::DEBUG, "Line To %g %g",coord[n],coord[n+1]);n+=2; break;
833 Log::getInstance()->log("OSD", Log::DEBUG, "Cubic To %g %g %g %g %g %g",coord[n],coord[n+1],coord[n+2],coord[n+3],coord[n+4],coord[n+5]);n+=6; break;
835 Log::getInstance()->log("OSD", Log::DEBUG, "Quad To %g %g %g %g",coord[n],coord[n+1],coord[n+2],coord[n+3]);n+=4; break;
837 Log::getInstance()->log("OSD", Log::DEBUG, "Close Path"); break;
841 //vguRect(path,0.f,0.f,1.f,1.f);
842 //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph %d %x",segments.size(),vgGetError());
844 VGfloat ori[]={0.f,0.f};
845 VGfloat esp[]={ft_face->glyph->advance.x/256.f*aspect_correction,ft_face->glyph->advance.y/256.f};
846 font_exp_x[glyph]=ft_face->glyph->advance.x/256.f*aspect_correction; //recalculate
848 vgSetGlyphToPath(vgfont,glyph,path,VG_FALSE,ori,esp);
849 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph %d %d %x",path,glyph,vgGetError());
850 if (path!=VG_INVALID_HANDLE) {
853 cur_char = FT_Get_Next_Char(ft_face,cur_char,&glyph);
859 void OsdOpenVG::drawSetTrans(SurfaceCommands & sc)
861 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
863 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
864 vgTranslate(0.f+sc.x,-576.f+sc.y);
866 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
868 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
869 vgTranslate(0.f+sc.x,-576.f+sc.y);
871 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
873 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
874 vgTranslate(0.f+sc.x,-576.f+sc.y);
880 //vgTranslate(0.f+sc.x,576.f-sc.y);
881 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Translate %g %g",sc.x,sc.y);
884 void OsdOpenVG::executeDrawCommand(SVGCommand & command)
887 VGfloat save_matrix[9];
888 VGfloat save_matrix2[9];
889 switch (command.instr) {
891 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
893 // rgba = vgGetColor((VGPaint) command.reference);
894 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Path %d %x %g %g %g %g",command.reference,command.target.path_index,command.x,command.y,command.w,command.h);
895 //vgSeti(VG_FILL_RULE,);
897 vgGetMatrix(save_matrix);
898 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
899 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
900 vgTranslate(command.x,command.y);
901 vgScale(command.w,command.h);
902 vgDrawPath(std_paths[command.target.path_index],VG_FILL_PATH);
903 vgLoadMatrix(save_matrix);
906 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
907 vgGetMatrix(save_matrix);
908 VGfloat imagewidth=vgGetParameteri((VGImage) command.target.image, VG_IMAGE_WIDTH);
909 VGfloat imageheight=vgGetParameteri((VGImage) command.target.image, VG_IMAGE_HEIGHT);
912 //vgScale(command.w,command.h);
914 if (command.reference) { //special behaviout for bw images they act as a mask on the current paint
915 vgTranslate(command.x,command.y);
916 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
917 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
918 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_STENCIL);
919 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
920 vgScale(aspect_correction,1.f);
921 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
922 vgGetMatrix(save_matrix2);
923 vgScale(imagewidth,imageheight);
926 //vgScale(720.f/((float)BACKBUFFER_WIDTH), 576.f/((float)BACKBUFFER_HEIGHT));
927 float scalex=command.w/imagewidth;
928 float scaley=command.h/imageheight;
931 if (command.corner == TopLeftLimited) {
932 if (imagewidth>imageheight && scalex!=0.f) {
934 ty+=(command.h-imageheight * scalex/aspect_correction)*0.5f;
936 if (imagewidth<imageheight && scaley!=0.f) {
938 tx+=(command.w-imagewidth * scaley*aspect_correction)*0.5f;
941 if (scalex==0.f && scaley==0.f) {
942 scalex=aspect_correction;
944 } else if (scalex==0.f) {
945 scalex=scaley*aspect_correction;
946 } else if (scaley==0.f) {
947 scaley=scalex/aspect_correction;
951 if (command.corner == BottomRight || command.corner == BottomLeft || command.corner == BottomMiddle)
953 ty-=imageheight * scaley;
956 if (command.corner == BottomRight || command.corner == TopRight)
958 tx-=imagewidth * scalex;
961 if (command.corner == BottomMiddle || command.corner == TopMiddle)
963 tx-=imagewidth * scalex *0.5f;
967 //vgScale(command.w/imagewidth,command.h/imageheight);
968 vgScale(scalex,scaley);
969 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
970 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
971 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia Draw Image Scale %g %g %g %g %g %g",command.w,imagewidth,command.h,imageheight,scalex,scaley);
976 //vgTranslate(200.f,500.f);
977 //vgScale(100.f,100.f);
979 vgDrawImage((VGImage) command.target.image);
980 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Image %d %x %g %g %g %g %x",command.reference,command.target.image,command.x,command.y,command.w,command.h,
982 if (command.reference) {
983 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
984 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
985 vgLoadMatrix(save_matrix2);
987 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
989 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
990 vgLoadMatrix(save_matrix);
993 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
994 vgGetMatrix(save_matrix);
995 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
996 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
997 vgTranslate(command.x,command.y);
998 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
999 vgGetMatrix(save_matrix2);
1000 unsigned int glyph_index=FT_Get_Char_Index(ft_face,command.target.textchar);
1001 vgScale(font_exp_x[glyph_index],font_height);
1004 VGfloat gori[]={0.,0.};
1005 vgSetfv(VG_GLYPH_ORIGIN,2,gori);
1008 vgDrawGlyph(vgfont,glyph_index,VG_FILL_PATH,VG_FALSE);
1009 //vgDrawPath(std_paths[Rectangle],VG_FILL_PATH);
1010 /* Log::getInstance()->log("OSD", Log::DEBUG, "Draw Glyph %d %c %d %g %g %x",command.reference,command.target.textchar,glyph_index,command.x,command.y,
1012 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1013 vgLoadMatrix(save_matrix);
1014 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1015 vgLoadMatrix(save_matrix2);
1017 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1020 cTeletextChar tchar;
1021 tchar.setInternal(command.target.ttchar);
1022 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1023 vgGetMatrix(save_matrix);
1024 enumTeletextColor ttforegcolour=tchar.GetFGColor();
1025 enumTeletextColor ttbackgcolour=tchar.GetBGColor();
1026 if (tchar.GetBoxedOut()) {
1027 ttforegcolour=ttcTransparent;
1028 ttbackgcolour=ttcTransparent;
1030 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_STENCIL);
1031 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1034 vgTranslate(command.x+command.w*11.85f*1.4f,command.y+command.h*19.75f);
1035 VGfloat gori[]={0.,0.};
1036 vgSetfv(VG_GLYPH_ORIGIN,2,gori);
1039 unsigned int color=Surface::enumTeletextColorToCoulour(ttbackgcolour).rgba();
1040 color=color<<8 | (color &0xff000000)>>24;
1041 vgSetColor(vgttpaint,color);
1042 vgSetPaint((VGPaint) vgttpaint,VG_FILL_PATH);
1043 vgSetPaint((VGPaint) vgttpaint,VG_STROKE_PATH);
1044 cTeletextChar filled;
1045 filled.setInternal(0x187f);
1046 unsigned int glyph_index=loadTTchar(filled);
1047 vgDrawGlyph(vgttfont,glyph_index,VG_FILL_PATH,VG_FALSE);
1049 color=Surface::enumTeletextColorToCoulour(ttforegcolour).rgba();
1050 color=color<<8 | (color &0xff000000)>>24;
1051 vgSetColor(vgttpaint,color);
1052 vgSetPaint((VGPaint) vgttpaint,VG_FILL_PATH);
1053 vgSetPaint((VGPaint) vgttpaint,VG_STROKE_PATH);
1054 glyph_index=loadTTchar(tchar);
1055 vgDrawGlyph(vgttfont,glyph_index,VG_FILL_PATH,VG_FALSE);
1057 /* Log::getInstance()->log("OSD", Log::DEBUG, "Draw TTchar %x %x %x %x",glyph_index,ttforegcolour,Surface::enumTeletextColorToCoulour(ttforegcolour).rgba(),
1058 vgGetColor(vgttpaint));*/
1061 vgLoadMatrix(save_matrix);
1062 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1063 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
1064 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
1067 case DrawClipping: {
1068 VGint coords[4]={0,0,0,0};
1069 coords[0]= ((command.x+clip_shift_x)*((float)BACKBUFFER_WIDTH)/720.f);
1070 coords[1]= ((576.f-command.y-clip_shift_y-command.h)*((float)BACKBUFFER_HEIGHT)/576.f);
1071 coords[2]= ((command.w-1.f)*((float)BACKBUFFER_WIDTH)/720.f);
1072 coords[3]= ((command.h-1.f)*((float)BACKBUFFER_HEIGHT)/576.f);
1073 vgSetiv(VG_SCISSOR_RECTS, 4,coords);
1074 if (command.w==0.f && command.h==0.f)
1075 vgSeti(VG_SCISSORING,VG_FALSE);
1076 else vgSeti(VG_SCISSORING,VG_TRUE);
1081 unsigned int OsdOpenVG::handleTask(OpenVGCommand& command)
1083 switch (command.task){
1084 case OVGreplacefont: {
1085 vgDestroyFont(vgfont);
1090 case OVGdestroyImageRef: {
1091 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia Draw Image Destroy %d ",command.param1);
1092 vgDestroyImage((VGImage)command.param1);
1095 case OVGdestroyPaint: {
1096 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint Destroy %d ",command.param1);
1097 vgDestroyPaint((VGPaint)command.param1);
1100 case OVGcreateImagePalette: {
1101 VGImage input=vgCreateImage(VG_A_8,command.param1, command.param2,
1102 VG_IMAGE_QUALITY_NONANTIALIASED|
1103 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
1104 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create palette %d %d %x %d",command.param1,command.param2,vgGetError(),input);
1105 vgImageSubData(input,command.data,command.param1,
1106 VG_A_8,0,0,command.param1, command.param2); // upload palettized image data
1107 VGImage handle=vgCreateImage(VG_sRGBA_8888,command.param1, command.param2,
1108 VG_IMAGE_QUALITY_NONANTIALIASED|
1109 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
1110 VGuint *palette=(VGuint*)malloc(256*sizeof(VGuint));
1111 VGuint *in_palette=(VGuint*)command.data2;
1112 for (int i=0;i<256;i++) {
1113 VGuint color=in_palette[i];
1114 palette[i]=color<<8 | (color &0xff000000)>>24;
1117 vgLookupSingle(handle,input,palette,VG_ALPHA,VG_FALSE,VG_FALSE);
1119 vgDestroyImage(input);
1123 case OVGcreateMonoBitmap: {
1124 VGImage handle=vgCreateImage(VG_A_1,command.param1, command.param2,
1125 VG_IMAGE_QUALITY_FASTER);
1126 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1127 unsigned int buffer_len=(command.param1*command.param2)>>3;
1128 unsigned char * buffer=(unsigned char*)malloc(buffer_len);
1129 unsigned char * r_buffer1=buffer;
1130 const unsigned char * r_buffer2=(const unsigned char *)command.data;
1131 unsigned char *buffer_end=buffer+buffer_len;
1132 while (r_buffer1!=buffer_end) {
1133 unsigned char byte=*r_buffer2;
1134 *r_buffer1=((byte * 0x0802LU & 0x22110LU) | (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
1135 r_buffer1++;r_buffer2++;
1139 vgImageSubData(handle,buffer,command.param1>>3,
1140 VG_A_1,0,0,command.param1, command.param2);
1142 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono2 %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1145 /*case OVGcreateImageFile: {
1148 Image *imagefile=(Image*)command.data;
1150 imagefile->write(&imageblob,"RGBA");
1153 handle=vgCreateImage(VG_sXBGR_8888,imagefile->columns(),imagefile->rows(),
1154 VG_IMAGE_QUALITY_BETTER);
1155 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark1",imagefile->columns(),imagefile->rows(),(unsigned int*)imageblob.data());
1156 vgImageSubData(handle,imageblob.data(),imagefile->columns()*4,
1157 VG_sXBGR_8888,0,0,imagefile->columns(),imagefile->rows());
1158 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark2",imagefile->columns(),imagefile->rows(),(unsigned int*)imageblob.data());
1160 }catch( Exception &error_ )
1162 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick hT: %s",error_.what());
1167 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create file %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1170 case OVGcreateImageMemory: {
1171 PictureInfo *info = (PictureInfo*) command.data;
1173 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateImageMemory");
1174 handle=vgCreateImage(VG_sABGR_8888,info->width,info->height,VG_IMAGE_QUALITY_BETTER);
1175 vgImageSubData(handle,info->image,info->width*4,
1176 VG_sABGR_8888,0,0,info->width,info->height);
1177 info->decoder->freeReference(info->reference);
1179 bool static_image=true;
1180 if (info->lindex & 0xffffffff) static_image=false;
1182 Message* m = new Message();
1183 // We have a pictures! send a message to ourself, to switch to gui thread
1185 m->to=Command::getInstance();
1186 m->parameter = handle;
1187 if (!static_image) {
1188 m->message=Message::NEW_PICTURE;
1189 m->tag = info->lindex;
1191 m->message=Message::NEW_PICTURE_STATIC;
1192 m->tag = info->lindex>> 32LL;
1194 m->tag = info->lindex;
1195 Command::getInstance()->postMessageFromOuterSpace(m); // inform command about new picture
1200 case OVGcreateEGLImage: {
1201 PictureInfo *info = (PictureInfo*) command.data;
1203 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateImageMemory %d %d",info->width,info->height);
1204 handle=vgCreateImage(VG_sABGR_8888,info->width,info->height,VG_IMAGE_QUALITY_BETTER);
1206 info->handle = handle;
1207 info->reference = eglCreateImageKHR(egl_display, egl_context, EGL_VG_PARENT_IMAGE_KHR, (EGLClientBuffer)handle, NULL);
1208 if (info->reference) return true;
1213 case OVGreadyEGLImage: {
1214 PictureInfo *info = (PictureInfo*) command.data;
1215 eglDestroyImageKHR(egl_display,info->reference);
1216 bool static_image=true;
1217 if (info->lindex & 0xffffffff) static_image=false;
1219 Message* m = new Message();
1221 m->to=Command::getInstance();
1222 m->parameter = info->handle;
1223 if (!static_image) {
1224 m->message=Message::NEW_PICTURE;
1225 m->tag = info->lindex;
1227 m->message=Message::NEW_PICTURE_STATIC;
1228 m->tag = info->lindex>> 32LL;
1230 Command::getInstance()->postMessageFromOuterSpace(m); // inform command about new picture
1237 case OVGcreateColorRef :{
1239 handle=vgCreatePaint();
1240 DrawStyle *style=(DrawStyle*)command.data;
1241 switch (style->ft) {
1242 case DrawStyle::Color: {
1243 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
1244 vgSetColor(handle,command.param1);
1246 rgba = vgGetColor((VGPaint)handle);
1247 Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint %d %x %x",handle,command.param1,rgba);
1249 case DrawStyle::GradientLinear: {
1250 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
1251 VGfloat params[]={style->x1,style->y1,style->x2,style->y2,style->r};
1252 Log::getInstance()->log("OSD", Log::DEBUG, "Draw Gradient %d %g %g %g %g",handle,params[0],params[1],params[2],params[3]);
1253 vgSetParameterfv(handle,VG_PAINT_LINEAR_GRADIENT,4,params);
1258 case DrawStyle::GradientRadial: {
1259 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
1260 VGfloat params[]={style->x1,style->y1,style->x2,style->y2,style->r};
1261 vgSetParameterfv(handle,VG_PAINT_RADIAL_GRADIENT,5,params);
1267 if (style->ft==DrawStyle::GradientLinear ||style->ft==DrawStyle::GradientRadial) {
1268 VGfloat colorramp[5*5];
1269 colorramp[0+0*5]=0.f;
1270 colorramp[1+0*5]=((float)style->red)/255.f;
1271 colorramp[2+0*5]=((float)style->green)/255.f;
1272 colorramp[3+0*5]=((float)style->blue)/255.f;
1273 colorramp[4+0*5]=((float)style->alpha)/255.f;
1274 for (int i=0;i<(style->num_colors-1);i++) {
1275 colorramp[0+(i+1)*5]=style->grad_pos[i];
1276 colorramp[1+(i+1)*5]=((float)style->grad_col[i].red)/255.f;
1277 colorramp[2+(i+1)*5]=((float)style->grad_col[i].green)/255.f;
1278 colorramp[3+(i+1)*5]=((float)style->grad_col[i].blue)/255.f;
1279 colorramp[4+(i+1)*5]=((float)style->grad_col[i].alpha)/255.f;
1281 colorramp[0+(style->num_colors)*5]=1.f;
1282 colorramp[1+(style->num_colors)*5]=((float)style->grad_col[style->num_colors-1].red)/255.f;
1283 colorramp[2+(style->num_colors)*5]=((float)style->grad_col[style->num_colors-1].green)/255.f;
1284 colorramp[3+(style->num_colors)*5]=((float)style->grad_col[style->num_colors-1].blue)/255.f;
1285 colorramp[4+(style->num_colors)*5]=((float)style->grad_col[style->num_colors-1].alpha)/255.f;
1286 vgSetParameteri(handle, VG_PAINT_COLOR_RAMP_SPREAD_MODE,VG_COLOR_RAMP_SPREAD_REFLECT);
1287 vgSetParameteri(handle, VG_PAINT_COLOR_RAMP_PREMULTIPLIED,VG_FALSE);
1288 vgSetParameterfv(handle,VG_PAINT_COLOR_RAMP_STOPS,5+(style->num_colors)*5,colorramp);
1293 case OVGimageUploadLine: {
1294 vgImageSubData((VGImage)command.param1,command.data,0,VG_sARGB_8888,0,command.param2,command.param3,1);
1301 bool OsdOpenVG::processTasks()
1306 while (vgcommands.size()>0)
1308 OpenVGCommand comm=vgcommands.front();
1309 vgcommands.pop_front();
1312 OpenVGResponse resp;
1313 resp.result=handleTask(comm);
1317 vgresponses.push_back(resp);
1321 //threadCheckExit();
1322 vgtaskSignal.signal();
1333 bool OsdOpenVG::haveOpenVGResponse(unsigned int id,unsigned int * resp)
1336 if (vgresponses.size()>0)
1338 deque<OpenVGResponse>::iterator itty=vgresponses.begin();
1339 while (itty!=vgresponses.end())
1341 if ((*itty).id==id) {
1342 *resp=(*itty).result;
1354 unsigned int OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm,bool wait)
1361 comm.id=0; // we are not waiting
1363 vgcommands.push_back(comm);
1368 if (!haveOpenVGResponse(comm.id,&resp)) {
1369 struct timespec target_time;
1370 clock_gettime(CLOCK_REALTIME,&target_time);
1371 target_time.tv_nsec+=1000000LL*100;
1372 if (target_time.tv_nsec>999999999) {
1373 target_time.tv_nsec-=1000000000L;
1374 target_time.tv_sec+=1;
1376 vgtaskSignal.waitForSignalTimed(&target_time);
1384 void OsdOpenVG::imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data)
1386 vgImageSubData((VGImage)index,data,0,VG_sARGB_8888,0,j,width,1);
1388 struct OpenVGCommand comm;
1389 comm.task=OVGimageUploadLine;
1394 putOpenVGCommand(comm,true);
1397 void OsdOpenVG::destroyImageRef(ImageIndex index)
1399 struct OpenVGCommand comm;
1400 comm.task=OVGdestroyImageRef;
1402 putOpenVGCommand(comm,false);
1405 ImageIndex OsdOpenVG::createJpeg(const char* fileName, int *width,int *height)
1407 Image* magicimage=NULL;
1408 struct OpenVGCommand comm;
1409 comm.task=OVGcreateImageFile;
1412 // Now figure out, if it is a special case
1413 if (strcmp(fileName,"/vdr.jpg")==0) {
1414 magicimage=new Image(Blob(vdr_data,vdr_data_end-vdr_data));
1415 *height=100; // this is faked so that the system does use the old coordinate system
1416 *width=ceil(190.f*aspect_correction);
1417 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm vdr.jpg");
1418 } else if (strcmp(fileName,"/wallpaperPAL.jpg")==0) {
1419 magicimage=new Image(Blob(wallpaper_data,wallpaper_data_end-wallpaper_data));
1420 *width=720; // this is faked so that the system does use the old coordinate system
1422 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm wallpaperPAL.jpg");
1424 magicimage=new Image();
1425 magicimage->read(fileName);
1426 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm file: %s",fileName);
1427 *width=ceil(magicimage->baseColumns()*aspect_correction); // this is faked so that the system does use the old coordinate system
1428 *height=magicimage->baseRows();
1431 }catch( Exception &error_ )
1433 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick: %s",error_.what());
1437 comm.data=magicimage;
1438 return putOpenVGCommand(comm,true);
1441 bool OsdOpenVG::getStaticImageData(unsigned int static_id, UCHAR **userdata, ULONG *length)
1443 switch (static_id) {
1445 *userdata = vdr_data;
1446 *length = vdr_data_end-vdr_data;
1450 *userdata = wallpaper_data;
1451 *length = wallpaper_data_end-wallpaper_data;
1462 void OsdOpenVG::createPicture(struct PictureInfo& pict_inf)
1464 struct OpenVGCommand comm;
1465 if (pict_inf.type == PictureInfo::RGBAMemBlock) {
1466 comm.task = OVGcreateImageMemory;
1467 comm.data = new PictureInfo(pict_inf);
1468 putOpenVGCommand(comm,false);
1469 } else if (pict_inf.type == PictureInfo::EGLImage) {
1470 comm.task = OVGreadyEGLImage;
1471 comm.data = new PictureInfo(pict_inf);
1472 putOpenVGCommand(comm,false);
1475 pict_inf.decoder->freeReference(pict_inf.reference);
1481 bool OsdOpenVG::getEGLPicture(struct OsdVector::PictureInfo & info , EGLDisplay * display)
1483 struct OpenVGCommand comm;
1484 info.type = PictureInfo::EGLImage;
1485 comm.task = OVGcreateEGLImage;
1487 *display = egl_display;
1488 return putOpenVGCommand(comm,true);
1493 ImageIndex OsdOpenVG::createMonoBitmap(void *base,int width,int height)
1495 struct OpenVGCommand comm;
1496 comm.task=OVGcreateMonoBitmap;
1500 return putOpenVGCommand(comm,true);
1503 ImageIndex OsdOpenVG::createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)
1505 struct OpenVGCommand comm;
1506 comm.task=OVGcreateImagePalette;
1509 comm.data=image_data;
1510 comm.data2=palette_data;
1511 return putOpenVGCommand(comm,true);
1514 void OsdOpenVG::destroyStyleRef(unsigned int index)
1516 struct OpenVGCommand comm;
1517 comm.task=OVGdestroyPaint;
1519 putOpenVGCommand(comm,false);
1522 unsigned int OsdOpenVG::createStyleRef(const DrawStyle &c)
1524 unsigned int col=c.rgba();
1525 struct OpenVGCommand comm;
1526 comm.task=OVGcreateColorRef;
1527 comm.param1=col<<8 | (col &0xff000000)>>24;
1529 return putOpenVGCommand(comm,true);
1532 unsigned int OsdOpenVG::createColorRef(const Colour &c)
1534 unsigned int col=c.rgba();
1535 struct OpenVGCommand comm;
1536 comm.task=OVGcreateColorRef;
1537 comm.param1=col<<8 | (col &0xff000000)>>24;
1539 return putOpenVGCommand(comm,true);