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"
30 #include "teletxt/txtfont.h"
32 #include <sys/syscall.h>
36 using namespace Magick;
38 extern uint8_t font_data[] asm("_binary_fonts_sourcesans_ttf_start");
39 extern uint8_t font_data_end[] asm("_binary_fonts_sourcesans_ttf_end");
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;
65 OsdOpenVG::~OsdOpenVG()
73 if (freetype_inited) FT_Done_Face(ft_face);
81 int OsdOpenVG::init(void* device)
83 if (initted) return 0;
84 Video* video = Video::getInstance();
85 //window=*((HWND*)device);
87 // May be this device specific part should go to a device specific child class
89 //init broadcom chipset (Move to video?)
92 //First get connection to egl
93 egl_display=eglGetDisplay(EGL_DEFAULT_DISPLAY);
95 if (egl_display==EGL_NO_DISPLAY) {
96 Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x",eglGetError());
103 if (eglInitialize(egl_display, NULL, NULL)==EGL_FALSE) {
104 Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x",eglGetError());
110 const char *query_str=eglQueryString(egl_display,EGL_CLIENT_APIS);
111 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
112 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());
113 query_str=eglQueryString(egl_display,EGL_EXTENSIONS);
114 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
115 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());
117 if (eglBindAPI(EGL_OPENVG_API)==EGL_FALSE) {
118 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api failed! %x",eglGetError());
123 const EGLint attributs[]={
124 EGL_RED_SIZE,8,EGL_GREEN_SIZE, 8,EGL_BLUE_SIZE, 8,EGL_ALPHA_SIZE, 8,
125 EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT,
126 EGL_CONFORMANT, EGL_OPENVG_BIT,
128 }; // Here, we might have to select the resolution!
133 if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number)==EGL_FALSE) {
134 Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %x",eglGetError());
141 egl_context=eglCreateContext(egl_display,egl_ourconfig,NULL,NULL);
142 if (egl_context==EGL_NO_CONTEXT) {
143 Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %x",eglGetError());
148 // warning broadcom specific, get display size!
149 display_width=display_height=0;
150 if (graphics_get_display_size(0, &display_width, &display_height)<0) {
151 Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) ");
155 Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height);
156 VC_RECT_T dst_rect ={0,0,display_width,display_height};
157 VC_RECT_T src_rect={0,0,BACKBUFFER_WIDTH <<16,BACKBUFFER_HEIGHT<<16};
158 // VC_RECT_T src_rect_bg={0,0,1<<16,1<<16};
159 // VC_RECT_T src_rect_im={0,0,1,1};
161 /* uint32_t back_image_ptr;
162 bcm_backres=vc_dispmanx_resource_create(VC_IMAGE_RGB888,1,1,&back_image_ptr);
163 unsigned int color=0x00FF0000;
164 vc_dispmanx_resource_write_data(bcm_backres,VC_IMAGE_RGB888,4,&color,&src_rect_im);*/
166 DISPMANX_UPDATE_HANDLE_T bcm_update;
167 bcm_display=vc_dispmanx_display_open(0);
168 bcm_update=vc_dispmanx_update_start(0);
169 bcm_element=vc_dispmanx_element_add(bcm_update,bcm_display,
171 &src_rect,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);
174 /* bcm_background=vc_dispmanx_element_add(bcm_update,bcm_display,
175 0,&dst_rect,bcm_backres ,
176 &src_rect_bg,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);*/
178 vc_dispmanx_update_submit_sync(bcm_update);
182 static EGL_DISPMANX_WINDOW_T nativewindow;
183 nativewindow.element=bcm_element;
184 nativewindow.height=BACKBUFFER_HEIGHT;
185 nativewindow.width=BACKBUFFER_WIDTH;
187 egl_surface = eglCreateWindowSurface(egl_display,egl_ourconfig, &nativewindow,NULL );
188 if (egl_surface==EGL_NO_SURFACE) {
189 Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!");
193 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current in1%d",syscall(SYS_gettid));
194 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
195 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed");
201 query_str=(const char*)vgGetString(VG_VERSION) ;
202 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
203 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
205 query_str=(const char*)vgGetString(VG_VENDOR) ;
206 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
207 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
209 query_str=(const char*)vgGetString(VG_RENDERER) ;
210 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
211 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
213 query_str=(const char*)vgGetString(VG_EXTENSIONS) ;
214 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
215 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
217 aspect_correction= ((float)BACKBUFFER_HEIGHT)/576.f/(((float)BACKBUFFER_WIDTH)/720.f);
222 vgttfont=vgCreateFont(0);
223 vgttpaint=vgCreatePaint();
224 vgSetParameteri( vgttpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
225 vgSetColor(vgttpaint,0xffffffff);
227 eglSwapInterval(egl_display, 1 );
229 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out 1%d",syscall(SYS_gettid));
230 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
231 //Now we will create the Screen
232 initted = 1; // must set this here or create surface won't work
235 /*if (((VideoOMX*)Video::getInstance())->initUsingOSDObjects()!=1) { //call Video for init stuff
238 InitializeMagick("");
240 pthread_cond_init(&vgtaskCond, NULL);
241 pthread_mutex_init(&vgtaskCondMutex, NULL);
252 void OsdOpenVG::initPaths()
257 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
258 VG_PATH_DATATYPE_F,1.f,0.f,
259 0,0,VG_PATH_CAPABILITY_ALL);
261 vguLine(current,0.f,0.f,1.f,0.f);
263 std_paths[HorzLine]=current;
265 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
266 VG_PATH_DATATYPE_F,1.f,0.f,
267 0,0,VG_PATH_CAPABILITY_ALL);
268 vguLine(current,0.f,0.f,0.f,1.f);
270 std_paths[VertLine]=current;
272 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
273 VG_PATH_DATATYPE_F,1.f,0.f,
274 0,0,VG_PATH_CAPABILITY_ALL);
275 //vguRect(current,0.f,0.f,1.f,1.f);
276 vguRect(current,0.f,0.f,1.f,1.f);
278 std_paths[Rectangle]=current;
280 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
281 VG_PATH_DATATYPE_F,1.f,0.f,
283 vguEllipse(current,0.f,0.f,1.f,1.f);
285 std_paths[Point]=current;
289 void OsdOpenVG::destroyPaths()
291 vgDestroyPath(std_paths[HorzLine]);
292 vgDestroyPath(std_paths[VertLine]);
293 vgDestroyPath(std_paths[Rectangle]);
294 vgDestroyPath(std_paths[Point]);
298 int OsdOpenVG::stopUpdate()
306 int OsdOpenVG::shutdown()
308 if (!initted) return 0;
311 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1");
313 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark2");
315 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark3");
319 //(((VideoOMX*)Video::getInstance())->shutdownUsingOSDObjects());
323 vgDestroyFont(vgfont);
324 vgDestroyFont(vgttfont);
325 vgDestroyPaint(vgttpaint);
327 vgClear(0,0,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT);
328 eglSwapBuffers(egl_display, egl_surface);
329 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out final");
330 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
331 eglDestroySurface(egl_display,egl_surface);
332 eglDestroyContext(egl_display,egl_context);
333 eglTerminate(egl_display );
335 DISPMANX_UPDATE_HANDLE_T bcm_update;
336 bcm_update=vc_dispmanx_update_start(0);
338 vc_dispmanx_element_remove(bcm_update,bcm_element);
339 // vc_dispmanx_element_remove(bcm_update,bcm_background);
340 vc_dispmanx_update_submit_sync(bcm_update);
341 // vc_dispmanx_resource_delete(bcm_backres);
342 vc_dispmanx_display_close(bcm_display);
352 void OsdOpenVG::threadMethod()
354 // We have to claim the egl context for this thread
356 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
357 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in thread %x",eglGetError());
364 unsigned int waittime=1;
368 long long time1 = getTimeMS();
369 if ((time1 - lastrendertime) > 200) {//5 fps for OSD updates are enough, avoids tearing
371 lastrendertime = getTimeMS();
374 if (processTasks()) ts=0;
378 struct timespec target_time;
379 clock_gettime(CLOCK_REALTIME,&target_time);
380 target_time.tv_nsec+=1000000LL*ts;
381 if (target_time.tv_nsec>999999999) {
382 target_time.tv_nsec-=1000000000L;
383 target_time.tv_sec+=1;
386 threadWaitForSignalTimed(&target_time);
391 //eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
395 void OsdOpenVG::threadPostStopCleanup()
406 void OsdOpenVG::InternalRendering(){
408 float colclear[]={1.f,1.0f,1.f,1.f};
409 vgSetfv(VG_CLEAR_COLOR,4,colclear);
410 vgClear(0,0,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT);
411 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
414 drawSurfaces(); //iterate through and draws all commands
416 //Show it to the user!
417 eglSwapBuffers(egl_display, egl_surface);
424 float OsdOpenVG::getFontHeight()
426 return font_height; //dummy
428 float OsdOpenVG::getCharWidth(wchar_t c)
430 unsigned int glyph_index=FT_Get_Char_Index(ft_face,c);
431 return font_exp_x[glyph_index];
434 unsigned int OsdOpenVG::loadTTchar(cTeletextChar c)
436 unsigned int glyph_index=c.getGlyphIndex();
437 if (tt_font_chars.find(glyph_index)!=tt_font_chars.end())
442 unsigned int buffer[10];
443 const VGfloat glyphOrigin[] = { 0.f, 0.f };
444 const VGfloat escapement[] = { 12.f, 0.f };
445 unsigned int * charmap = GetFontChar(c, buffer);
446 if (!charmap) { //invalid char
449 for (int i=0;i<10;i++) {
450 buffer[i]=charmap[i]>>4;
453 VGImage handle = vgCreateImage(
457 VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER
458 | VG_IMAGE_QUALITY_BETTER);
459 vgImageSubData(handle, buffer, 4, VG_A_1, 0, 0, 12, 10);
463 handle, glyphOrigin, escapement);
464 vgDestroyImage(handle);
465 tt_font_chars[glyph_index]=1;
470 int OsdOpenVG::loadFont()
473 float font_size=16.f;
474 if (!freetype_inited) {
475 error=FT_Init_FreeType(&ft_library);
478 Log::getInstance()->log("OSD", Log::WARN, "Could not load freetype %x",error);
482 error=FT_New_Memory_Face(ft_library,font_data,font_data_end-font_data,0,&ft_face );
484 Log::getInstance()->log("OSD", Log::WARN, "Could not load font face %x",error);
487 error=FT_Set_Char_Size(ft_face,0,font_size*64,0,0 /*dpi*/);
489 FT_Done_Face(ft_face);
490 Log::getInstance()->log("OSD", Log::WARN, "Could not set face size %x",error);
493 freetype_inited=true;
495 vgfont=vgCreateFont(0);
498 font_height=ft_face->size->metrics.height/64.f;
499 cur_char = FT_Get_First_Char(ft_face,&glyph);
500 vector<VGubyte> segments;
501 vector<VGfloat> coord;
502 segments.reserve(256);
504 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph test %d %x %x %d",cur_char,font_data_end,font_data,glyph);
507 error=FT_Load_Glyph(ft_face,glyph,FT_LOAD_DEFAULT);
509 FT_Done_Face(ft_face);
510 Log::getInstance()->log("OSD", Log::WARN, "Could not load glyph %x",error);
514 FT_Outline ot=ft_face->glyph->outline;
518 if (ot.n_contours ==0) {
519 path=VG_INVALID_HANDLE;
521 path=vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
522 1.0f,0.f,0,0,VG_PATH_CAPABILITY_ALL);
525 FT_Vector *pt=ot.points;
526 const char *tags=ot.tags;
527 const short* cont=ot.contours;
528 short n_cont=ot.n_contours;
529 short n_point=ot.n_points;
531 for (short point=0;n_cont!=0;cont++,n_cont--) {
532 short next_cont=*cont+1;
535 short first_point=point;
536 //Log::getInstance()->log("OSD", Log::DEBUG, "runs %d",*cont);
537 for (;point<next_cont;point++) {
538 char tag=tags[point];
539 FT_Vector fpoint=pt[point];
540 // Log::getInstance()->log("OSD", Log::DEBUG, "tag %d point %d %d: %d %d",tag,fpoint.x,fpoint.y,point,n_point);
542 segments.push_back(VG_MOVE_TO);
544 } else if (tag &0x1) { //on curve
546 segments.push_back(VG_LINE_TO);
547 } else if (last_tag &0x2){
548 segments.push_back(VG_CUBIC_TO);
550 segments.push_back(VG_QUAD_TO);
555 if (!(last_tag &0x1)) {
556 segments.push_back(VG_QUAD_TO);
557 int coord_size=coord.size();
558 VGfloat x=(coord[coord_size-2]+ ((float)fpoint.x)/64.f)*0.5f*aspect_correction;
559 VGfloat y=(coord[coord_size-1]+(font_size- ((float)fpoint.y)/64.f))*0.5f;
568 coord.push_back(((float)fpoint.x)*aspect_correction/64.);
569 coord.push_back(font_size-((float)fpoint.y)/64.);
570 //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]);
572 if (!(last_tag &0x1)) {
574 segments.push_back(VG_CUBIC_TO);
576 segments.push_back(VG_QUAD_TO);
578 coord.push_back(((float)pt[first_point].x)*aspect_correction/64.);
579 coord.push_back(font_size-((float)pt[first_point].y)/64.);
581 //segments.push_back(VG_CLOSE_PATH);
585 vgAppendPathData(path,segments.size(),&segments[0],&coord[0]);
587 /* for (int m=0;m<segments.size();m++) {
591 Log::getInstance()->log("OSD", Log::DEBUG, "Move To %g %g",coord[n],coord[n+1]);n+=2; break;
593 Log::getInstance()->log("OSD", Log::DEBUG, "Line To %g %g",coord[n],coord[n+1]);n+=2; break;
595 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;
597 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;
599 Log::getInstance()->log("OSD", Log::DEBUG, "Close Path"); break;
603 //vguRect(path,0.f,0.f,1.f,1.f);
604 //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph %d %x",segments.size(),vgGetError());
606 VGfloat ori[]={0.f,0.f};
607 VGfloat esp[]={ft_face->glyph->advance.x/64.f*aspect_correction,ft_face->glyph->advance.y/64.f};
608 font_exp_x[glyph]=ft_face->glyph->advance.x/64.f*aspect_correction; //recalculate
610 vgSetGlyphToPath(vgfont,glyph,path,VG_FALSE,ori,esp);
611 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph %d %d %x",path,glyph,vgGetError());
612 if (path!=VG_INVALID_HANDLE) {
615 cur_char = FT_Get_Next_Char(ft_face,cur_char,&glyph);
621 void OsdOpenVG::drawSetTrans(SurfaceCommands & sc)
623 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
625 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
626 vgTranslate(0.f+sc.x,-576.f+sc.y);
628 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
630 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
631 vgTranslate(0.f+sc.x,-576.f+sc.y);
633 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
635 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
636 vgTranslate(0.f+sc.x,-576.f+sc.y);
640 //vgTranslate(0.f+sc.x,576.f-sc.y);
641 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Translate %g %g",sc.x,sc.y);
644 void OsdOpenVG::executeDrawCommand(SVGCommand & command)
647 VGfloat save_matrix[9];
648 switch (command.instr) {
650 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
652 // rgba = vgGetColor((VGPaint) command.reference);
653 //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);
654 //vgSeti(VG_FILL_RULE,);
656 vgGetMatrix(save_matrix);
657 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
658 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
659 vgTranslate(command.x,command.y);
660 vgScale(command.w,command.h);
661 vgDrawPath(std_paths[command.target.path_index],VG_FILL_PATH);
662 vgLoadMatrix(save_matrix);
665 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
666 vgGetMatrix(save_matrix);
667 vgTranslate(command.x,command.y);
668 //vgScale(command.w,command.h);
669 if (command.reference) { //special behaviout for bw images they act as a mask on the current paint
670 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
671 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
672 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_STENCIL);
673 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
674 vgScale(aspect_correction,1.f);
676 VGfloat imagewidth=vgGetParameteri((VGImage) command.target.image, VG_IMAGE_WIDTH);
677 VGfloat imageheight=vgGetParameteri((VGImage) command.target.image, VG_IMAGE_HEIGHT);
678 //vgScale(720.f/((float)BACKBUFFER_WIDTH), 576.f/((float)BACKBUFFER_HEIGHT));
679 float scalex=command.w/imagewidth;
680 float scaley=command.h/imageheight;
681 //vgScale(command.w/imagewidth,command.h/imageheight);
682 vgScale(scalex,scaley);
683 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
684 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Image Scale %g %g %g %g %g %g",command.w,imagewidth,command.h,imageheight,scalex,scaley);
689 //vgTranslate(200.f,500.f);
690 //vgScale(100.f,100.f);
692 vgDrawImage((VGImage) command.target.image);
693 //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,
695 if (command.reference) {
696 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
697 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
699 vgLoadMatrix(save_matrix);
702 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
703 vgGetMatrix(save_matrix);
704 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
705 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
706 vgTranslate(command.x,command.y);
707 VGfloat gori[]={0.,0.};
708 vgSetfv(VG_GLYPH_ORIGIN,2,gori);
710 unsigned int glyph_index=FT_Get_Char_Index(ft_face,command.target.textchar);
711 vgDrawGlyph(vgfont,glyph_index,VG_FILL_PATH,VG_FALSE);
712 //vgDrawPath(std_paths[Rectangle],VG_FILL_PATH);
713 /* 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,
715 vgLoadMatrix(save_matrix);
716 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
720 tchar.setInternal(command.target.ttchar);
721 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
722 vgGetMatrix(save_matrix);
723 enumTeletextColor ttforegcolour=tchar.GetFGColor();
724 enumTeletextColor ttbackgcolour=tchar.GetBGColor();
725 if (tchar.GetBoxedOut()) {
726 ttforegcolour=ttcTransparent;
727 ttbackgcolour=ttcTransparent;
729 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_STENCIL);
730 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
733 vgTranslate(command.x+command.w*11.85f*1.4f,command.y+command.h*19.75f);
734 VGfloat gori[]={0.,0.};
735 vgSetfv(VG_GLYPH_ORIGIN,2,gori);
738 unsigned int color=Surface::enumTeletextColorToCoulour(ttbackgcolour).rgba();
739 color=color<<8 | (color &0xff000000)>>24;
740 vgSetColor(vgttpaint,color);
741 vgSetPaint((VGPaint) vgttpaint,VG_FILL_PATH);
742 vgSetPaint((VGPaint) vgttpaint,VG_STROKE_PATH);
743 cTeletextChar filled;
744 filled.setInternal(0x187f);
745 unsigned int glyph_index=loadTTchar(filled);
746 vgDrawGlyph(vgttfont,glyph_index,VG_FILL_PATH,VG_FALSE);
748 color=Surface::enumTeletextColorToCoulour(ttforegcolour).rgba();
749 color=color<<8 | (color &0xff000000)>>24;
750 vgSetColor(vgttpaint,color);
751 vgSetPaint((VGPaint) vgttpaint,VG_FILL_PATH);
752 vgSetPaint((VGPaint) vgttpaint,VG_STROKE_PATH);
753 glyph_index=loadTTchar(tchar);
754 vgDrawGlyph(vgttfont,glyph_index,VG_FILL_PATH,VG_FALSE);
756 /* Log::getInstance()->log("OSD", Log::DEBUG, "Draw TTchar %x %x %x %x",glyph_index,ttforegcolour,Surface::enumTeletextColorToCoulour(ttforegcolour).rgba(),
757 vgGetColor(vgttpaint));*/
760 vgLoadMatrix(save_matrix);
761 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
762 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
763 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
769 unsigned int OsdOpenVG::handleTask(OpenVGCommand& command)
771 switch (command.task){
772 case OVGdestroyImageRef: {
773 vgDestroyImage((VGImage)command.param1);
776 case OVGdestroyPaint: {
777 Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint Destroy %d ",command.param1);
778 vgDestroyPaint((VGPaint)command.param1);
781 case OVGcreateImagePalette: {
782 VGImage input=vgCreateImage(VG_A_8,command.param1, command.param2,
783 VG_IMAGE_QUALITY_NONANTIALIASED|
784 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
785 vgImageSubData(input,command.data,command.param1,
786 VG_A_8,0,0,command.param1, command.param2); // upload palettized image data
787 VGImage handle=vgCreateImage(VG_sRGBA_8888,command.param1, command.param2,
788 VG_IMAGE_QUALITY_NONANTIALIASED|
789 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
790 VGuint *palette=(VGuint*)malloc(256*sizeof(VGuint));
791 VGuint *in_palette=(VGuint*)command.data2;
792 for (int i=0;i<256;i++) {
793 VGuint color=in_palette[i];
794 palette[i]=color<<8 | (color &0xff000000)>>24;
797 vgLookupSingle(handle,input,palette,VG_ALPHA,VG_FALSE,VG_FALSE);
799 vgDestroyImage(input);
803 case OVGcreateMonoBitmap: {
804 VGImage handle=vgCreateImage(VG_A_1,command.param1, command.param2,
805 VG_IMAGE_QUALITY_NONANTIALIASED|
806 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
807 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
808 unsigned int buffer_len=(command.param1*command.param2)>>3;
809 unsigned char * buffer=(unsigned char*)malloc(buffer_len);
810 unsigned char * r_buffer1=buffer;
811 const unsigned char * r_buffer2=(const unsigned char *)command.data;
812 unsigned char *buffer_end=buffer+buffer_len;
813 while (r_buffer1!=buffer_end) {
814 unsigned char byte=*r_buffer2;
815 *r_buffer1=((byte * 0x0802LU & 0x22110LU) | (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
816 r_buffer1++;r_buffer2++;
820 vgImageSubData(handle,buffer,command.param1>>3,
821 VG_A_1,0,0,command.param1, command.param2);
823 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono2 %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
826 case OVGcreateImageFile: {
829 Image *imagefile=(Image*)command.data;
831 imagefile->write(&imageblob,"RGBA");
834 handle=vgCreateImage(VG_sXBGR_8888,imagefile->columns(),imagefile->rows(),
835 VG_IMAGE_QUALITY_NONANTIALIASED|
836 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
837 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark1",imagefile->columns(),imagefile->rows(),*(unsigned int*)imageblob.data());
838 vgImageSubData(handle,imageblob.data(),imagefile->columns()*4,
839 VG_sXBGR_8888,0,0,imagefile->columns(),imagefile->rows());
840 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark2",imagefile->columns(),imagefile->rows(),*(unsigned int*)imageblob.data());
842 }catch( Exception &error_ )
844 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick hT: %s",error_.what());
849 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create file %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
852 case OVGcreateColorRef :{
854 handle=vgCreatePaint();
855 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
856 vgSetColor(handle,command.param1);
858 rgba = vgGetColor((VGPaint)handle);
859 Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint %d %x %x",handle,command.param1,rgba);
862 case OVGimageUploadLine: {
863 vgImageSubData((VGImage)command.param1,command.data,0,VG_sARGB_8888,0,command.param2,command.param3,1);
870 bool OsdOpenVG::processTasks()
875 while (vgcommands.size()>0)
877 OpenVGCommand &comm=vgcommands.front();
879 resp.result=handleTask(comm);
882 vgresponses.push_back(resp);
884 vgcommands.pop_front();
888 pthread_mutex_lock(&vgtaskCondMutex);
889 pthread_cond_signal(&vgtaskCond);
890 pthread_mutex_unlock(&vgtaskCondMutex);
901 bool OsdOpenVG::haveOpenVGResponse(unsigned int id,unsigned int * resp)
904 if (vgresponses.size()>0)
906 deque<OpenVGResponse>::iterator itty=vgresponses.begin();
907 while (itty!=vgresponses.end())
909 if ((*itty).id==id) {
910 *resp=(*itty).result;
922 unsigned int OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm,bool wait)
929 comm.id=0; // we are not waiting
931 vgcommands.push_back(comm);
936 if (!haveOpenVGResponse(comm.id,&resp)) {
937 struct timespec target_time;
938 clock_gettime(CLOCK_REALTIME,&target_time);
939 target_time.tv_nsec+=1000000LL*100;
940 if (target_time.tv_nsec>999999999) {
941 target_time.tv_nsec-=1000000000L;
942 target_time.tv_sec+=1;
944 pthread_mutex_lock(&vgtaskCondMutex);
945 pthread_cond_timedwait(&vgtaskCond, &vgtaskCondMutex,&target_time);
946 pthread_mutex_unlock(&vgtaskCondMutex);
954 void OsdOpenVG::imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data)
956 vgImageSubData((VGImage)index,data,0,VG_sARGB_8888,0,j,width,1);
958 struct OpenVGCommand comm;
959 comm.task=OVGimageUploadLine;
964 putOpenVGCommand(comm,true);
967 void OsdOpenVG::destroyImageRef(ImageIndex index)
969 struct OpenVGCommand comm;
970 comm.task=OVGdestroyImageRef;
972 putOpenVGCommand(comm,false);
975 ImageIndex OsdOpenVG::createJpeg(const char* fileName, int *width,int *height)
977 Image* magicimage=NULL;
979 struct OpenVGCommand comm;
980 comm.task=OVGcreateImageFile;
983 // Now figure out, if it is a special case
984 if (strcmp(fileName,"/vdr.jpg")==0) {
985 magicimage=new Image(Blob(vdr_data,vdr_data_end-vdr_data));
986 *height=100; // this is faked so that the system does use the old coordinate system
987 *width=ceil(190.f*aspect_correction);
988 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm vdr.jpg");
989 } else if (strcmp(fileName,"/wallpaperPAL.jpg")==0) {
990 magicimage=new Image(Blob(wallpaper_data,wallpaper_data_end-wallpaper_data));
991 *width=720; // this is faked so that the system does use the old coordinate system
993 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm wallpaperPAL.jpg");
995 magicimage=new Image();
996 magicimage->read(fileName);
997 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm file: %s",fileName);
998 *width=ceil(magicimage->baseColumns()*aspect_correction); // this is faked so that the system does use the old coordinate system
999 *height=magicimage->baseRows();
1002 }catch( Exception &error_ )
1004 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick: %s",error_.what());
1008 comm.data=magicimage;
1009 return putOpenVGCommand(comm,true);
1012 ImageIndex OsdOpenVG::createMonoBitmap(void *base,int width,int height)
1014 struct OpenVGCommand comm;
1015 comm.task=OVGcreateMonoBitmap;
1019 return putOpenVGCommand(comm,true);
1022 ImageIndex OsdOpenVG::createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)
1024 struct OpenVGCommand comm;
1025 comm.task=OVGcreateImagePalette;
1028 comm.data=image_data;
1029 comm.data2=palette_data;
1030 return putOpenVGCommand(comm,true);
1033 void OsdOpenVG::destroyStyleRef(unsigned int index)
1035 struct OpenVGCommand comm;
1036 comm.task=OVGdestroyPaint;
1038 putOpenVGCommand(comm,false);
1041 unsigned int OsdOpenVG::createStyleRef(const DrawStyle &c)
1043 unsigned int col=c.rgba();
1044 struct OpenVGCommand comm;
1045 comm.task=OVGcreateColorRef;
1046 comm.param1=col<<8 | (col &0xff000000)>>24;
1048 return putOpenVGCommand(comm,true);
1051 unsigned int OsdOpenVG::createColorRef(const Colour &c)
1053 unsigned int col=c.rgba();
1054 struct OpenVGCommand comm;
1055 comm.task=OVGcreateColorRef;
1056 comm.param1=col<<8 | (col &0xff000000)>>24;
1058 return putOpenVGCommand(comm,true);