2 Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
22 #include "osdopenvg.h"
\r
24 #include "videoomx.h"
\r
25 #include "surface.h"
\r
26 #include <Magick++.h>
\r
28 #include "message.h"
\r
29 #include "command.h"
\r
30 #include "teletxt/txtfont.h"
\r
32 #include <sys/syscall.h>
\r
36 using namespace Magick;
\r
38 extern uint8_t font_data[] asm("_binary_fonts_sourcesans_ttf_start");
\r
39 extern uint8_t font_data_end[] asm("_binary_fonts_sourcesans_ttf_end");
\r
40 extern uint8_t vdr_data[] asm("_binary_other_vdrhires_jpg_start");
\r
41 extern uint8_t vdr_data_end[] asm("_binary_other_vdrhires_jpg_end");
\r
42 extern uint8_t wallpaper_data[] asm("_binary_other_wallpaper720p_jpg_start");
\r
43 extern uint8_t wallpaper_data_end[] asm("_binary_other_wallpaper720p_jpg_end");
\r
46 #define BACKBUFFER_WIDTH 1280
\r
47 #define BACKBUFFER_HEIGHT 720
\r
50 OsdOpenVG::OsdOpenVG()
\r
54 lastrendertime=getTimeMS();
\r
58 aspect_correction=1.;
\r
64 OsdOpenVG::~OsdOpenVG()
\r
79 int OsdOpenVG::init(void* device)
\r
81 if (initted) return 0;
\r
82 Video* video = Video::getInstance();
\r
83 //window=*((HWND*)device);
\r
85 // May be this device specific part should go to a device specific child class
\r
87 //init broadcom chipset (Move to video?)
\r
90 //First get connection to egl
\r
91 egl_display=eglGetDisplay(EGL_DEFAULT_DISPLAY);
\r
93 if (egl_display==EGL_NO_DISPLAY) {
\r
94 Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x",eglGetError());
\r
101 if (eglInitialize(egl_display, NULL, NULL)==EGL_FALSE) {
\r
102 Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x",eglGetError());
\r
108 const char *query_str=eglQueryString(egl_display,EGL_CLIENT_APIS);
\r
109 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
110 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());
\r
111 query_str=eglQueryString(egl_display,EGL_EXTENSIONS);
\r
112 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
113 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",eglGetError());
\r
115 if (eglBindAPI(EGL_OPENVG_API)==EGL_FALSE) {
\r
116 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api failed! %x",eglGetError());
\r
121 const EGLint attributs[]={
\r
122 EGL_RED_SIZE,8,EGL_GREEN_SIZE, 8,EGL_BLUE_SIZE, 8,EGL_ALPHA_SIZE, 8,
\r
123 EGL_SURFACE_TYPE, EGL_WINDOW_BIT|EGL_PBUFFER_BIT,
\r
124 EGL_CONFORMANT, EGL_OPENVG_BIT,
\r
126 }; // Here, we might have to select the resolution!
\r
131 if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number)==EGL_FALSE) {
\r
132 Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %x",eglGetError());
\r
139 egl_context=eglCreateContext(egl_display,egl_ourconfig,NULL,NULL);
\r
140 if (egl_context==EGL_NO_CONTEXT) {
\r
141 Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %x",eglGetError());
\r
146 // warning broadcom specific, get display size!
\r
147 display_width=display_height=0;
\r
148 if (graphics_get_display_size(0, &display_width, &display_height)<0) {
\r
149 Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) ");
\r
153 Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height);
\r
154 VC_RECT_T dst_rect ={0,0,display_width,display_height};
\r
155 VC_RECT_T src_rect={0,0,BACKBUFFER_WIDTH <<16,BACKBUFFER_HEIGHT<<16};
\r
156 // VC_RECT_T src_rect_bg={0,0,1<<16,1<<16};
\r
157 // VC_RECT_T src_rect_im={0,0,1,1};
\r
159 /* uint32_t back_image_ptr;
\r
160 bcm_backres=vc_dispmanx_resource_create(VC_IMAGE_RGB888,1,1,&back_image_ptr);
\r
161 unsigned int color=0x00FF0000;
\r
162 vc_dispmanx_resource_write_data(bcm_backres,VC_IMAGE_RGB888,4,&color,&src_rect_im);*/
\r
164 DISPMANX_UPDATE_HANDLE_T bcm_update;
\r
165 bcm_display=vc_dispmanx_display_open(0);
\r
166 bcm_update=vc_dispmanx_update_start(0);
\r
167 bcm_element=vc_dispmanx_element_add(bcm_update,bcm_display,
\r
169 &src_rect,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);
\r
172 /* bcm_background=vc_dispmanx_element_add(bcm_update,bcm_display,
\r
173 0,&dst_rect,bcm_backres ,
\r
174 &src_rect_bg,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);*/
\r
176 vc_dispmanx_update_submit_sync(bcm_update);
\r
180 static EGL_DISPMANX_WINDOW_T nativewindow;
\r
181 nativewindow.element=bcm_element;
\r
182 nativewindow.height=BACKBUFFER_HEIGHT;
\r
183 nativewindow.width=BACKBUFFER_WIDTH;
\r
185 egl_surface = eglCreateWindowSurface(egl_display,egl_ourconfig, &nativewindow,NULL );
\r
186 if (egl_surface==EGL_NO_SURFACE) {
\r
187 Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!");
\r
191 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current in1%d",syscall(SYS_gettid));
\r
192 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
\r
193 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed");
\r
199 query_str=(const char*)vgGetString(VG_VERSION) ;
\r
200 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
201 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
\r
203 query_str=(const char*)vgGetString(VG_VENDOR) ;
\r
204 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
205 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
\r
207 query_str=(const char*)vgGetString(VG_RENDERER) ;
\r
208 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
209 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
\r
211 query_str=(const char*)vgGetString(VG_EXTENSIONS) ;
\r
212 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
\r
213 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x",vgGetError());
\r
215 aspect_correction= ((float)BACKBUFFER_HEIGHT)/576.f/(((float)BACKBUFFER_WIDTH)/720.f);
\r
220 vgttfont=vgCreateFont(0);
\r
221 vgttpaint=vgCreatePaint();
\r
222 vgSetParameteri( vgttpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
\r
223 vgSetColor(vgttpaint,0xffffffff);
\r
225 eglSwapInterval(egl_display, 1 );
\r
227 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out 1%d",syscall(SYS_gettid));
\r
228 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
\r
229 //Now we will create the Screen
\r
230 initted = 1; // must set this here or create surface won't work
\r
233 /*if (((VideoOMX*)Video::getInstance())->initUsingOSDObjects()!=1) { //call Video for init stuff
\r
236 InitializeMagick("");
\r
238 pthread_cond_init(&vgtaskCond, NULL);
\r
239 pthread_mutex_init(&vgtaskCondMutex, NULL);
\r
242 taskmutex.Unlock();
\r
250 void OsdOpenVG::initPaths()
\r
255 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
\r
256 VG_PATH_DATATYPE_F,1.f,0.f,
\r
257 0,0,VG_PATH_CAPABILITY_ALL);
\r
259 vguLine(current,0.f,0.f,1.f,0.f);
\r
261 std_paths[HorzLine]=current;
\r
263 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
\r
264 VG_PATH_DATATYPE_F,1.f,0.f,
\r
265 0,0,VG_PATH_CAPABILITY_ALL);
\r
266 vguLine(current,0.f,0.f,0.f,1.f);
\r
268 std_paths[VertLine]=current;
\r
270 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
\r
271 VG_PATH_DATATYPE_F,1.f,0.f,
\r
272 0,0,VG_PATH_CAPABILITY_ALL);
\r
273 //vguRect(current,0.f,0.f,1.f,1.f);
\r
274 vguRect(current,0.f,0.f,1.f,1.f);
\r
276 std_paths[Rectangle]=current;
\r
278 current=vgCreatePath(VG_PATH_FORMAT_STANDARD,
\r
279 VG_PATH_DATATYPE_F,1.f,0.f,
\r
281 vguEllipse(current,0.f,0.f,1.f,1.f);
\r
283 std_paths[Point]=current;
\r
287 void OsdOpenVG::destroyPaths()
\r
289 vgDestroyPath(std_paths[HorzLine]);
\r
290 vgDestroyPath(std_paths[VertLine]);
\r
291 vgDestroyPath(std_paths[Rectangle]);
\r
292 vgDestroyPath(std_paths[Point]);
\r
296 int OsdOpenVG::stopUpdate()
\r
304 int OsdOpenVG::shutdown()
\r
306 if (!initted) return 0;
\r
309 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1");
\r
311 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark2");
\r
313 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark3");
\r
317 //(((VideoOMX*)Video::getInstance())->shutdownUsingOSDObjects());
\r
319 FT_Done_Face(ft_face);
\r
320 vgDestroyFont(vgfont);
\r
321 vgDestroyFont(vgttfont);
\r
322 vgDestroyPaint(vgttpaint);
\r
324 vgClear(0,0,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT);
\r
325 eglSwapBuffers(egl_display, egl_surface);
\r
326 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out final");
\r
327 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
\r
328 eglDestroySurface(egl_display,egl_surface);
\r
329 eglDestroyContext(egl_display,egl_context);
\r
330 eglTerminate(egl_display );
\r
332 DISPMANX_UPDATE_HANDLE_T bcm_update;
\r
333 bcm_update=vc_dispmanx_update_start(0);
\r
335 vc_dispmanx_element_remove(bcm_update,bcm_element);
\r
336 // vc_dispmanx_element_remove(bcm_update,bcm_background);
\r
337 vc_dispmanx_update_submit_sync(bcm_update);
\r
338 // vc_dispmanx_resource_delete(bcm_backres);
\r
339 vc_dispmanx_display_close(bcm_display);
\r
349 void OsdOpenVG::threadMethod()
\r
351 // We have to claim the egl context for this thread
\r
353 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)== EGL_FALSE) {
\r
354 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in thread %x",eglGetError());
\r
361 unsigned int waittime=1;
\r
365 long long time1 = getTimeMS();
\r
366 if ((time1 - lastrendertime) > 200) {//5 fps for OSD updates are enough, avoids tearing
\r
367 InternalRendering();
\r
368 lastrendertime = getTimeMS();
\r
371 if (processTasks()) ts=0;
\r
375 struct timespec target_time;
\r
376 clock_gettime(CLOCK_REALTIME,&target_time);
\r
377 target_time.tv_nsec+=1000000LL*ts;
\r
378 if (target_time.tv_nsec>999999999) {
\r
379 target_time.tv_nsec-=1000000000L;
\r
380 target_time.tv_sec+=1;
\r
383 threadWaitForSignalTimed(&target_time);
\r
388 //eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
\r
392 void OsdOpenVG::threadPostStopCleanup()
\r
403 void OsdOpenVG::InternalRendering(){
\r
405 float colclear[]={1.f,1.0f,1.f,1.f};
\r
406 vgSetfv(VG_CLEAR_COLOR,4,colclear);
\r
407 vgClear(0,0,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT);
\r
408 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
\r
411 drawSurfaces(); //iterate through and draws all commands
\r
413 //Show it to the user!
\r
414 eglSwapBuffers(egl_display, egl_surface);
\r
421 float OsdOpenVG::getFontHeight()
\r
423 return font_height; //dummy
\r
425 float OsdOpenVG::getCharWidth(wchar_t c)
\r
427 unsigned int glyph_index=FT_Get_Char_Index(ft_face,c);
\r
428 return font_exp_x[glyph_index];
\r
431 unsigned int OsdOpenVG::loadTTchar(cTeletextChar c)
\r
433 unsigned int glyph_index=c.getGlyphIndex();
\r
434 if (tt_font_chars.find(glyph_index)!=tt_font_chars.end())
\r
436 return glyph_index;
\r
439 unsigned int buffer[10];
\r
440 const VGfloat glyphOrigin[] = { 0.f, 0.f };
\r
441 const VGfloat escapement[] = { 12.f, 0.f };
\r
442 unsigned int * charmap = GetFontChar(c, buffer);
\r
443 if (!charmap) { //invalid char
\r
446 for (int i=0;i<10;i++) {
\r
447 buffer[i]=charmap[i]>>4;
\r
450 VGImage handle = vgCreateImage(
\r
454 VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER
\r
455 | VG_IMAGE_QUALITY_BETTER);
\r
456 vgImageSubData(handle, buffer, 4, VG_A_1, 0, 0, 12, 10);
\r
460 handle, glyphOrigin, escapement);
\r
461 vgDestroyImage(handle);
\r
462 tt_font_chars[glyph_index]=1;
\r
464 return glyph_index;
\r
467 int OsdOpenVG::loadFont()
\r
469 int error=FT_Init_FreeType(&ft_library);
\r
470 float font_size=16.f;
\r
473 Log::getInstance()->log("OSD", Log::WARN, "Could not load freetype %x",error);
\r
477 error=FT_New_Memory_Face(ft_library,font_data,font_data_end-font_data,0,&ft_face );
\r
479 Log::getInstance()->log("OSD", Log::WARN, "Could not load font face %x",error);
\r
482 error=FT_Set_Char_Size(ft_face,0,font_size*64,0,0 /*dpi*/);
\r
484 FT_Done_Face(ft_face);
\r
485 Log::getInstance()->log("OSD", Log::WARN, "Could not set face size %x",error);
\r
488 vgfont=vgCreateFont(0);
\r
491 font_height=ft_face->size->metrics.height/64.f;
\r
492 cur_char = FT_Get_First_Char(ft_face,&glyph);
\r
493 vector<VGubyte> segments;
\r
494 vector<VGfloat> coord;
\r
495 segments.reserve(256);
\r
496 coord.reserve(1024);
\r
497 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph test %d %x %x %d",cur_char,font_data_end,font_data,glyph);
\r
500 error=FT_Load_Glyph(ft_face,glyph,FT_LOAD_DEFAULT);
\r
502 FT_Done_Face(ft_face);
\r
503 Log::getInstance()->log("OSD", Log::WARN, "Could not load glyph %x",error);
\r
507 FT_Outline ot=ft_face->glyph->outline;
\r
511 if (ot.n_contours ==0) {
\r
512 path=VG_INVALID_HANDLE;
\r
514 path=vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
\r
515 1.0f,0.f,0,0,VG_PATH_CAPABILITY_ALL);
\r
517 /* convert glyph */
\r
518 FT_Vector *pt=ot.points;
\r
519 const char *tags=ot.tags;
\r
520 const short* cont=ot.contours;
\r
521 short n_cont=ot.n_contours;
\r
522 short n_point=ot.n_points;
\r
524 for (short point=0;n_cont!=0;cont++,n_cont--) {
\r
525 short next_cont=*cont+1;
\r
528 short first_point=point;
\r
529 //Log::getInstance()->log("OSD", Log::DEBUG, "runs %d",*cont);
\r
530 for (;point<next_cont;point++) {
\r
531 char tag=tags[point];
\r
532 FT_Vector fpoint=pt[point];
\r
533 // Log::getInstance()->log("OSD", Log::DEBUG, "tag %d point %d %d: %d %d",tag,fpoint.x,fpoint.y,point,n_point);
\r
535 segments.push_back(VG_MOVE_TO);
\r
537 } else if (tag &0x1) { //on curve
\r
538 if (last_tag &0x1) {
\r
539 segments.push_back(VG_LINE_TO);
\r
540 } else if (last_tag &0x2){
\r
541 segments.push_back(VG_CUBIC_TO);
\r
543 segments.push_back(VG_QUAD_TO);
\r
548 if (!(last_tag &0x1)) {
\r
549 segments.push_back(VG_QUAD_TO);
\r
550 int coord_size=coord.size();
\r
551 VGfloat x=(coord[coord_size-2]+ ((float)fpoint.x)/64.f)*0.5f*aspect_correction;
\r
552 VGfloat y=(coord[coord_size-1]+(font_size- ((float)fpoint.y)/64.f))*0.5f;
\r
553 coord.push_back(x);
\r
554 coord.push_back(y);
\r
561 coord.push_back(((float)fpoint.x)*aspect_correction/64.);
\r
562 coord.push_back(font_size-((float)fpoint.y)/64.);
\r
563 //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]);
\r
565 if (!(last_tag &0x1)) {
\r
566 if (last_tag &0x2) {
\r
567 segments.push_back(VG_CUBIC_TO);
\r
569 segments.push_back(VG_QUAD_TO);
\r
571 coord.push_back(((float)pt[first_point].x)*aspect_correction/64.);
\r
572 coord.push_back(font_size-((float)pt[first_point].y)/64.);
\r
574 //segments.push_back(VG_CLOSE_PATH);
\r
578 vgAppendPathData(path,segments.size(),&segments[0],&coord[0]);
\r
580 /* for (int m=0;m<segments.size();m++) {
\r
581 switch (segments[m])
\r
584 Log::getInstance()->log("OSD", Log::DEBUG, "Move To %g %g",coord[n],coord[n+1]);n+=2; break;
\r
586 Log::getInstance()->log("OSD", Log::DEBUG, "Line To %g %g",coord[n],coord[n+1]);n+=2; break;
\r
588 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;
\r
590 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;
\r
591 case VG_CLOSE_PATH:
\r
592 Log::getInstance()->log("OSD", Log::DEBUG, "Close Path"); break;
\r
596 //vguRect(path,0.f,0.f,1.f,1.f);
\r
597 //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph %d %x",segments.size(),vgGetError());
\r
599 VGfloat ori[]={0.f,0.f};
\r
600 VGfloat esp[]={ft_face->glyph->advance.x/64.f*aspect_correction,ft_face->glyph->advance.y/64.f};
\r
601 font_exp_x[glyph]=ft_face->glyph->advance.x/64.f*aspect_correction; //recalculate
\r
603 vgSetGlyphToPath(vgfont,glyph,path,VG_FALSE,ori,esp);
\r
604 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph %d %d %x",path,glyph,vgGetError());
\r
605 if (path!=VG_INVALID_HANDLE) {
\r
606 vgDestroyPath(path);
\r
608 cur_char = FT_Get_Next_Char(ft_face,cur_char,&glyph);
\r
614 void OsdOpenVG::drawSetTrans(SurfaceCommands & sc)
\r
616 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
\r
618 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
\r
619 vgTranslate(0.f+sc.x,-576.f+sc.y);
\r
621 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
\r
623 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
\r
624 vgTranslate(0.f+sc.x,-576.f+sc.y);
\r
626 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
\r
628 vgScale(((float)BACKBUFFER_WIDTH)/720.f, -((float)BACKBUFFER_HEIGHT)/576.f);
\r
629 vgTranslate(0.f+sc.x,-576.f+sc.y);
\r
633 //vgTranslate(0.f+sc.x,576.f-sc.y);
\r
634 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Translate %g %g",sc.x,sc.y);
\r
637 void OsdOpenVG::executeDrawCommand(SVGCommand & command)
\r
640 VGfloat save_matrix[9];
\r
641 switch (command.instr) {
\r
643 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
\r
645 // rgba = vgGetColor((VGPaint) command.reference);
\r
646 //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);
\r
647 //vgSeti(VG_FILL_RULE,);
\r
649 vgGetMatrix(save_matrix);
\r
650 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
\r
651 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
\r
652 vgTranslate(command.x,command.y);
\r
653 vgScale(command.w,command.h);
\r
654 vgDrawPath(std_paths[command.target.path_index],VG_FILL_PATH);
\r
655 vgLoadMatrix(save_matrix);
\r
658 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
\r
659 vgGetMatrix(save_matrix);
\r
660 vgTranslate(command.x,command.y);
\r
661 //vgScale(command.w,command.h);
\r
662 if (command.reference) { //special behaviout for bw images they act as a mask on the current paint
\r
663 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
\r
664 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
\r
665 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_STENCIL);
\r
666 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
\r
667 vgScale(aspect_correction,1.f);
\r
669 VGfloat imagewidth=vgGetParameteri((VGImage) command.target.image, VG_IMAGE_WIDTH);
\r
670 VGfloat imageheight=vgGetParameteri((VGImage) command.target.image, VG_IMAGE_HEIGHT);
\r
671 //vgScale(720.f/((float)BACKBUFFER_WIDTH), 576.f/((float)BACKBUFFER_HEIGHT));
\r
672 float scalex=command.w/imagewidth;
\r
673 float scaley=command.h/imageheight;
\r
674 //vgScale(command.w/imagewidth,command.h/imageheight);
\r
675 vgScale(scalex,scaley);
\r
676 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
\r
677 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Image Scale %g %g %g %g %g %g",command.w,imagewidth,command.h,imageheight,scalex,scaley);
\r
681 //vgLoadIdentity();
\r
682 //vgTranslate(200.f,500.f);
\r
683 //vgScale(100.f,100.f);
\r
685 vgDrawImage((VGImage) command.target.image);
\r
686 //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,
\r
688 if (command.reference) {
\r
689 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
\r
690 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
\r
692 vgLoadMatrix(save_matrix);
\r
695 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
\r
696 vgGetMatrix(save_matrix);
\r
697 vgSetPaint((VGPaint) command.reference,VG_FILL_PATH);
\r
698 vgSetPaint((VGPaint) command.reference,VG_STROKE_PATH);
\r
699 vgTranslate(command.x,command.y);
\r
700 VGfloat gori[]={0.,0.};
\r
701 vgSetfv(VG_GLYPH_ORIGIN,2,gori);
\r
703 unsigned int glyph_index=FT_Get_Char_Index(ft_face,command.target.textchar);
\r
704 vgDrawGlyph(vgfont,glyph_index,VG_FILL_PATH,VG_FALSE);
\r
705 //vgDrawPath(std_paths[Rectangle],VG_FILL_PATH);
\r
706 /* 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,
\r
708 vgLoadMatrix(save_matrix);
\r
709 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
\r
712 cTeletextChar tchar;
\r
713 tchar.setInternal(command.target.ttchar);
\r
714 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
\r
715 vgGetMatrix(save_matrix);
\r
716 enumTeletextColor ttforegcolour=tchar.GetFGColor();
\r
717 enumTeletextColor ttbackgcolour=tchar.GetBGColor();
\r
718 if (tchar.GetBoxedOut()) {
\r
719 ttforegcolour=ttcTransparent;
\r
720 ttbackgcolour=ttcTransparent;
\r
722 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_STENCIL);
\r
723 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
\r
726 vgTranslate(command.x+command.w*11.85f*1.4f,command.y+command.h*19.75f);
\r
727 VGfloat gori[]={0.,0.};
\r
728 vgSetfv(VG_GLYPH_ORIGIN,2,gori);
\r
730 vgScale(-1.4f,2.f);
\r
731 unsigned int color=Surface::enumTeletextColorToCoulour(ttbackgcolour).rgba();
\r
732 color=color<<8 | (color &0xff000000)>>24;
\r
733 vgSetColor(vgttpaint,color);
\r
734 vgSetPaint((VGPaint) vgttpaint,VG_FILL_PATH);
\r
735 vgSetPaint((VGPaint) vgttpaint,VG_STROKE_PATH);
\r
736 cTeletextChar filled;
\r
737 filled.setInternal(0x187f);
\r
738 unsigned int glyph_index=loadTTchar(filled);
\r
739 vgDrawGlyph(vgttfont,glyph_index,VG_FILL_PATH,VG_FALSE);
\r
741 color=Surface::enumTeletextColorToCoulour(ttforegcolour).rgba();
\r
742 color=color<<8 | (color &0xff000000)>>24;
\r
743 vgSetColor(vgttpaint,color);
\r
744 vgSetPaint((VGPaint) vgttpaint,VG_FILL_PATH);
\r
745 vgSetPaint((VGPaint) vgttpaint,VG_STROKE_PATH);
\r
746 glyph_index=loadTTchar(tchar);
\r
747 vgDrawGlyph(vgttfont,glyph_index,VG_FILL_PATH,VG_FALSE);
\r
749 /* Log::getInstance()->log("OSD", Log::DEBUG, "Draw TTchar %x %x %x %x",glyph_index,ttforegcolour,Surface::enumTeletextColorToCoulour(ttforegcolour).rgba(),
\r
750 vgGetColor(vgttpaint));*/
\r
753 vgLoadMatrix(save_matrix);
\r
754 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
\r
755 vgSeti(VG_IMAGE_MODE,VG_DRAW_IMAGE_NORMAL);
\r
756 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
\r
762 unsigned int OsdOpenVG::handleTask(OpenVGCommand& command)
\r
764 switch (command.task){
\r
765 case OVGdestroyImageRef: {
\r
766 vgDestroyImage((VGImage)command.param1);
\r
769 case OVGdestroyPaint: {
\r
770 Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint Destroy %d ",command.param1);
\r
771 vgDestroyPaint((VGPaint)command.param1);
\r
774 case OVGcreateImagePalette: {
\r
775 VGImage input=vgCreateImage(VG_A_8,command.param1, command.param2,
\r
776 VG_IMAGE_QUALITY_NONANTIALIASED|
\r
777 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
\r
778 vgImageSubData(input,command.data,command.param1,
\r
779 VG_A_8,0,0,command.param1, command.param2); // upload palettized image data
\r
780 VGImage handle=vgCreateImage(VG_sRGBA_8888,command.param1, command.param2,
\r
781 VG_IMAGE_QUALITY_NONANTIALIASED|
\r
782 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
\r
783 VGuint *palette=(VGuint*)malloc(256*sizeof(VGuint));
\r
784 VGuint *in_palette=(VGuint*)command.data2;
\r
785 for (int i=0;i<256;i++) {
\r
786 VGuint color=in_palette[i];
\r
787 palette[i]=color<<8 | (color &0xff000000)>>24;
\r
790 vgLookupSingle(handle,input,palette,VG_ALPHA,VG_FALSE,VG_FALSE);
\r
792 vgDestroyImage(input);
\r
796 case OVGcreateMonoBitmap: {
\r
797 VGImage handle=vgCreateImage(VG_A_1,command.param1, command.param2,
\r
798 VG_IMAGE_QUALITY_NONANTIALIASED|
\r
799 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
\r
800 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
\r
801 unsigned int buffer_len=(command.param1*command.param2)>>3;
\r
802 unsigned char * buffer=(unsigned char*)malloc(buffer_len);
\r
803 unsigned char * r_buffer1=buffer;
\r
804 const unsigned char * r_buffer2=(const unsigned char *)command.data;
\r
805 unsigned char *buffer_end=buffer+buffer_len;
\r
806 while (r_buffer1!=buffer_end) {
\r
807 unsigned char byte=*r_buffer2;
\r
808 *r_buffer1=((byte * 0x0802LU & 0x22110LU) | (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
\r
809 r_buffer1++;r_buffer2++;
\r
813 vgImageSubData(handle,buffer,command.param1>>3,
\r
814 VG_A_1,0,0,command.param1, command.param2);
\r
816 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono2 %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
\r
819 case OVGcreateImageFile: {
\r
822 Image *imagefile=(Image*)command.data;
\r
824 imagefile->write(&imageblob,"RGBA");
\r
827 handle=vgCreateImage(VG_sXBGR_8888,imagefile->columns(),imagefile->rows(),
\r
828 VG_IMAGE_QUALITY_NONANTIALIASED|
\r
829 VG_IMAGE_QUALITY_FASTER|VG_IMAGE_QUALITY_BETTER);
\r
830 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark1",imagefile->columns(),imagefile->rows(),*(unsigned int*)imageblob.data());
\r
831 vgImageSubData(handle,imageblob.data(),imagefile->columns()*4,
\r
832 VG_sXBGR_8888,0,0,imagefile->columns(),imagefile->rows());
\r
833 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark2",imagefile->columns(),imagefile->rows(),*(unsigned int*)imageblob.data());
\r
835 }catch( Exception &error_ )
\r
837 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick hT: %s",error_.what());
\r
842 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create file %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
\r
845 case OVGcreateColorRef :{
\r
847 handle=vgCreatePaint();
\r
848 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
\r
849 vgSetColor(handle,command.param1);
\r
851 rgba = vgGetColor((VGPaint)handle);
\r
852 Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint %d %x %x",handle,command.param1,rgba);
\r
855 case OVGimageUploadLine: {
\r
856 vgImageSubData((VGImage)command.param1,command.data,0,VG_sARGB_8888,0,command.param2,command.param3,1);
\r
863 bool OsdOpenVG::processTasks()
\r
868 while (vgcommands.size()>0)
\r
870 OpenVGCommand &comm=vgcommands.front();
\r
871 OpenVGResponse resp;
\r
872 resp.result=handleTask(comm);
\r
875 vgresponses.push_back(resp);
\r
877 vgcommands.pop_front();
\r
878 taskmutex.Unlock();
\r
880 //threadCheckExit();
\r
881 pthread_mutex_lock(&vgtaskCondMutex);
\r
882 pthread_cond_signal(&vgtaskCond);
\r
883 pthread_mutex_unlock(&vgtaskCondMutex);
\r
888 taskmutex.Unlock();
\r
894 bool OsdOpenVG::haveOpenVGResponse(unsigned int id,unsigned int * resp)
\r
897 if (vgresponses.size()>0)
\r
899 deque<OpenVGResponse>::iterator itty=vgresponses.begin();
\r
900 while (itty!=vgresponses.end())
\r
902 if ((*itty).id==id) {
\r
903 *resp=(*itty).result;
\r
904 taskmutex.Unlock();
\r
910 taskmutex.Unlock();
\r
915 unsigned int OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm,bool wait)
\r
922 comm.id=0; // we are not waiting
\r
924 vgcommands.push_back(comm);
\r
925 taskmutex.Unlock();
\r
929 if (!haveOpenVGResponse(comm.id,&resp)) {
\r
930 struct timespec target_time;
\r
931 clock_gettime(CLOCK_REALTIME,&target_time);
\r
932 target_time.tv_nsec+=1000000LL*100;
\r
933 if (target_time.tv_nsec>999999999) {
\r
934 target_time.tv_nsec-=1000000000L;
\r
935 target_time.tv_sec+=1;
\r
937 pthread_mutex_lock(&vgtaskCondMutex);
\r
938 pthread_cond_timedwait(&vgtaskCond, &vgtaskCondMutex,&target_time);
\r
939 pthread_mutex_unlock(&vgtaskCondMutex);
\r
947 void OsdOpenVG::imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data)
\r
949 vgImageSubData((VGImage)index,data,0,VG_sARGB_8888,0,j,width,1);
\r
951 struct OpenVGCommand comm;
\r
952 comm.task=OVGimageUploadLine;
\r
957 putOpenVGCommand(comm,true);
\r
960 void OsdOpenVG::destroyImageRef(ImageIndex index)
\r
962 struct OpenVGCommand comm;
\r
963 comm.task=OVGdestroyImageRef;
\r
965 putOpenVGCommand(comm,false);
\r
968 ImageIndex OsdOpenVG::createJpeg(const char* fileName, int *width,int *height)
\r
970 Image* magicimage=NULL;
\r
972 struct OpenVGCommand comm;
\r
973 comm.task=OVGcreateImageFile;
\r
976 // Now figure out, if it is a special case
\r
977 if (strcmp(fileName,"/vdr.jpg")==0) {
\r
978 magicimage=new Image(Blob(vdr_data,vdr_data_end-vdr_data));
\r
979 *height=100; // this is faked so that the system does use the old coordinate system
\r
980 *width=ceil(190.f*aspect_correction);
\r
981 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm vdr.jpg");
\r
982 } else if (strcmp(fileName,"/wallpaperPAL.jpg")==0) {
\r
983 magicimage=new Image(Blob(wallpaper_data,wallpaper_data_end-wallpaper_data));
\r
984 *width=720; // this is faked so that the system does use the old coordinate system
\r
986 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm wallpaperPAL.jpg");
\r
988 magicimage=new Image();
\r
989 magicimage->read(fileName);
\r
990 Log::getInstance()->log("OSD", Log::DEBUG, "LoadIm file: %s",fileName);
\r
991 *width=ceil(magicimage->baseColumns()*aspect_correction); // this is faked so that the system does use the old coordinate system
\r
992 *height=magicimage->baseRows();
\r
995 }catch( Exception &error_ )
\r
997 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick: %s",error_.what());
\r
1001 comm.data=magicimage;
\r
1002 return putOpenVGCommand(comm,true);
\r
1005 ImageIndex OsdOpenVG::createMonoBitmap(void *base,int width,int height)
\r
1007 struct OpenVGCommand comm;
\r
1008 comm.task=OVGcreateMonoBitmap;
\r
1009 comm.param1=width;
\r
1010 comm.param2=height;
\r
1012 return putOpenVGCommand(comm,true);
\r
1015 ImageIndex OsdOpenVG::createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)
\r
1017 struct OpenVGCommand comm;
\r
1018 comm.task=OVGcreateImagePalette;
\r
1019 comm.param1=width;
\r
1020 comm.param2=height;
\r
1021 comm.data=image_data;
\r
1022 comm.data2=palette_data;
\r
1023 return putOpenVGCommand(comm,true);
\r
1026 void OsdOpenVG::destroyStyleRef(unsigned int index)
\r
1028 struct OpenVGCommand comm;
\r
1029 comm.task=OVGdestroyPaint;
\r
1030 comm.param1=index;
\r
1031 putOpenVGCommand(comm,false);
\r
1034 unsigned int OsdOpenVG::createStyleRef(const DrawStyle &c)
\r
1036 unsigned int col=c.rgba();
\r
1037 struct OpenVGCommand comm;
\r
1038 comm.task=OVGcreateColorRef;
\r
1039 comm.param1=col<<8 | (col &0xff000000)>>24;
\r
1041 return putOpenVGCommand(comm,true);
\r
1044 unsigned int OsdOpenVG::createColorRef(const Colour &c)
\r
1046 unsigned int col=c.rgba();
\r
1047 struct OpenVGCommand comm;
\r
1048 comm.task=OVGcreateColorRef;
\r
1049 comm.param1=col<<8 | (col &0xff000000)>>24;
\r
1051 return putOpenVGCommand(comm,true);
\r