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, see <https://www.gnu.org/licenses/>.
20 #include <stdio.h> // really?
22 #include <sys/syscall.h>
23 #include <fontconfig/fontconfig.h>
30 #include "messagequeue.h"
31 #include "teletxt/txtfont.h"
33 #include "osdopenvg.h"
35 #define EXTERNALPICTURE(name, fname, fileextension) extern uint8_t name ## _data[] asm("_binary_other_"#fname"_"#fileextension"_start"); \
36 extern uint8_t name ## _data_end[] asm("_binary_other_"#fname"_"#fileextension"_end");
40 #undef EXTERNALPICTURE
42 #define BACKBUFFER_WIDTH 1280
43 #define BACKBUFFER_HEIGHT 720
45 OsdOpenVG::OsdOpenVG()
49 lastrendertime = getTimeMS();
51 const char* fontname = "Droid Sans:style=Regular";
52 cur_fontname = static_cast<char*>(malloc(strlen(fontname) + 1));
53 strcpy(cur_fontname, fontname);
55 #define EXTERNALPICTURE(name, fname, fileextension) static_artwork_begin[sa_ ## name]=name ## _data;
59 #undef EXTERNALPICTURE
60 #define EXTERNALPICTURE(name, fname, fileextension) static_artwork_end[sa_ ## name]=name ## _data_end;
64 #undef EXTERNALPICTURE
67 OsdOpenVG::~OsdOpenVG()
69 if (initted) shutdown();
71 if (cur_fontname) free(cur_fontname);
73 if (freetype_inited) FT_Done_Face(ft_face);
75 for (char* c : fontnames) free(c);
76 for (char* c : fontnames_keys) free(c);
84 if (initted) return 0;
88 //First get connection to egl
89 egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
90 if (egl_display == EGL_NO_DISPLAY)
92 Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x", eglGetError());
97 if (eglInitialize(egl_display, NULL, NULL) == EGL_FALSE)
99 Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x", eglGetError());
104 const char* query_str = eglQueryString(egl_display, EGL_CLIENT_APIS);
106 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
107 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", eglGetError());
109 query_str = eglQueryString(egl_display, EGL_EXTENSIONS);
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());
114 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
116 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api failed! %x", eglGetError());
121 const EGLint attributs[] =
123 EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
124 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
125 EGL_CONFORMANT, EGL_OPENVG_BIT,
127 }; // Here, we might have to select the resolution!
131 if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number) == EGL_FALSE)
133 Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %x", eglGetError());
138 egl_context = eglCreateContext(egl_display, egl_ourconfig, NULL, NULL);
140 if (egl_context == EGL_NO_CONTEXT)
142 Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %x", eglGetError());
147 // warning broadcom specific, get display size!
148 display_width = display_height = 0;
150 if (graphics_get_display_size(0, &display_width, &display_height) < 0)
152 Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) ");
157 Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ", display_width, display_height);
158 VC_RECT_T dst_rect = {0, 0, (int32_t)display_width, (int32_t)display_height};
159 VC_RECT_T src_rect = {0, 0, BACKBUFFER_WIDTH << 16, BACKBUFFER_HEIGHT << 16};
160 VC_RECT_T src_rect_bg = {0, 0, 16 << 16, 16 << 16};
161 // VC_RECT_T src_rect_im={0,0,16,16};
163 uint32_t back_image_ptr;
164 bcm_backres = vc_dispmanx_resource_create(VC_IMAGE_RGBX32, 16, 16, &back_image_ptr);
166 updateBackgroundColor(DrawStyle::WALLPAPER);
168 DISPMANX_UPDATE_HANDLE_T bcm_update;
169 bcm_display = vc_dispmanx_display_open(0);
170 bcm_update = vc_dispmanx_update_start(0);
171 bcm_element = vc_dispmanx_element_add(bcm_update, bcm_display,
173 &src_rect, DISPMANX_PROTECTION_NONE, 0, 0, (DISPMANX_TRANSFORM_T) 0);
176 bcm_background = vc_dispmanx_element_add(bcm_update, bcm_display,
177 0, &dst_rect, bcm_backres,
178 &src_rect_bg, DISPMANX_PROTECTION_NONE, 0, 0, (DISPMANX_TRANSFORM_T) 0);
180 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)
190 Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!");
195 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current in1%d", syscall(SYS_gettid));
197 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
199 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed");
206 query_str = reinterpret_cast<const char*>(vgGetString(VG_VERSION));
208 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
209 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", vgGetError());
211 query_str = reinterpret_cast<const char*>(vgGetString(VG_VENDOR));
213 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
214 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", vgGetError());
216 query_str = reinterpret_cast<const char*>(vgGetString(VG_RENDERER));
218 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
219 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", vgGetError());
221 query_str = reinterpret_cast<const char*>(vgGetString(VG_EXTENSIONS));
223 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
224 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", vgGetError());
226 aspect_correction = ((float)BACKBUFFER_HEIGHT) / 576.f / (((float)BACKBUFFER_WIDTH) / 720.f);
229 if (!fontnames.size())
231 //inspired by and copied from vdr's code
233 FcObjectSet* objset = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
234 FcPattern* pattern = FcPatternCreate();
235 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
236 FcFontSet* fonts = FcFontList(NULL, pattern, objset);
238 for (int i = 0; i < fonts->nfont; i++)
240 char* s = (char*)FcNameUnparse(fonts->fonts[i]);
244 char* c = strchr(s, ':');
248 char* s2 = strchr(c + 1, ',');
253 char* p = strchr(s, ',');
258 else memmove(p, c, strlen(c) + 1);
261 char* key = (char*)malloc(strlen(s) + 1);
263 fontnames_keys.push_back(key);
264 char* s2 = strstr(s, "style=");
268 memmove(s2, s2 + 6, strlen(s2 + 6) + 1);
271 fontnames.push_back(s);
275 FcFontSetDestroy(fonts);
276 FcPatternDestroy(pattern);
277 FcObjectSetDestroy(objset);
280 if (!loadFont(false))
285 vgttfont = vgCreateFont(0);
286 vgttpaint = vgCreatePaint();
287 vgSetParameteri( vgttpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
288 vgSetColor(vgttpaint, 0xffffffff);
290 eglSwapInterval(egl_display, 1);
292 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out 1%d", syscall(SYS_gettid));
293 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
294 //Now we will create the Screen
295 initted = true; // must set this here or create surface won't work
297 /*if (((VideoOMX*)Video::getInstance())->initUsingOSDObjects()!=1) { //call Video for init stuff
305 #ifdef PICTURE_DECODER_OMX
306 imageomx = new ImageOMX(&reader);
307 reader.addDecoder(imageomx);
313 void OsdOpenVG::updateBackgroundColor(DrawStyle bg)
315 unsigned int color[16 * 16];
317 if (!bcm_backres) return;
319 VC_RECT_T src_rect_im = {0, 0, 16, 16};
321 if (bg.ft != DrawStyle::GradientLinear)
326 //memset(color,0xFF,sizeof(unsigned int)*4*8);
327 for (int j = 0; j < 16; j++)
329 int helpr = (((15 - j) * bg.red) + (j * bg.grad_col[0].red)) / 15;
330 int helpb = (((15 - j) * bg.blue) + (j * bg.grad_col[0].blue)) / 15;
331 int helpg = (((15 - j) * bg.green) + (j * bg.grad_col[0].green)) / 15;
332 //unsigned int cur_col=help | (help<< 8) | (help<< 16) | (0xFF<< 24);
333 unsigned int cur_col = helpr | (helpg << (8)) | (helpb << (16)) | (0xFF << (24));
335 for (int i = 0; i < 16; i++)
337 color[i + 16 * j] = cur_col;
341 vc_dispmanx_resource_write_data(bcm_backres, VC_IMAGE_RGBX32, 16 * 4, color, &src_rect_im);
344 void OsdOpenVG::getScreenSize(int& width, int& height)
346 width = BACKBUFFER_WIDTH;
347 height = BACKBUFFER_HEIGHT;
350 void OsdOpenVG::getRealScreenSize(int& width, int& height)
352 width = display_width;
353 height = display_height;
356 bool OsdOpenVG::screenShot(void* buffer, int width, int height, bool osd /*include osd*/)
358 if (!initted) return false;
360 if (!buffer) return false;
362 DISPMANX_RESOURCE_HANDLE_T res;
363 DISPMANX_DISPLAY_HANDLE_T display;
367 res = vc_dispmanx_resource_create(VC_IMAGE_RGBA32, width, height, &image_ptr);
368 display = vc_dispmanx_display_open(0);
372 vc_dispmanx_snapshot(display, res,
373 static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_NO_RGB | DISPMANX_SNAPSHOT_FILL/*|DISPMANX_SNAPSHOT_PACK*/));
377 vc_dispmanx_snapshot(display, res,
378 static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_FILL));
381 vc_dispmanx_rect_set(&rect, 0, 0, width, height);
382 vc_dispmanx_resource_read_data(res, &rect, buffer, width * 4);
383 vc_dispmanx_resource_delete(res);
384 vc_dispmanx_display_close(display);
388 void OsdOpenVG::initPaths()
391 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
392 VG_PATH_DATATYPE_F, 1.f, 0.f,
393 0, 0, VG_PATH_CAPABILITY_ALL);
395 vguLine(current, 0.f, 0.f, 1.f, 0.f);
397 std_paths[PIHorzLine] = current;
399 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
400 VG_PATH_DATATYPE_F, 1.f, 0.f,
401 0, 0, VG_PATH_CAPABILITY_ALL);
402 vguLine(current, 0.f, 0.f, 0.f, 1.f);
404 std_paths[PIVertLine] = current;
406 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
407 VG_PATH_DATATYPE_F, 1.f, 0.f,
408 0, 0, VG_PATH_CAPABILITY_ALL);
409 //vguRect(current,0.f,0.f,1.f,1.f);
410 vguRect(current, 0.f, 0.f, 1.f, 1.f);
412 std_paths[PIRectangle] = current;
414 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
415 VG_PATH_DATATYPE_F, 1.f, 0.f,
417 vguEllipse(current, 0.f, 0.f, 1.f, 1.f);
419 std_paths[PIPoint] = current;
422 void OsdOpenVG::destroyPaths()
424 vgDestroyPath(std_paths[PIHorzLine]);
425 vgDestroyPath(std_paths[PIVertLine]);
426 vgDestroyPath(std_paths[PIRectangle]);
427 vgDestroyPath(std_paths[PIPoint]);
430 int OsdOpenVG::stopUpdate()
433 processOpenVGCommands();
438 void OsdOpenVG::purgeAllReferences()
441 drawstyleHandlesRefCounts.clear(); // remove all references
444 map<void *,ImageIndex>::iterator mitty=monobitmaps.begin();
445 while (mitty!=monobitmaps.end()) {
446 vgDestroyImage((VGImage)(*mitty).second);
451 / *map<string,ImageIndex>::iterator jitty=jpegs.begin();
452 while (jitty!=jpegs.end()) {
453 vgDestroyImage((VGImage)(*jitty).second);
458 map<TVMediaInfo,ImageIndex>::iterator titty=tvmedias.begin();
459 while (titty!=tvmedias.end()) {
460 vgDestroyImage((VGImage)(*titty).second);
465 map<pair<Colour*,unsigned int>,unsigned int>::iterator sitty=drawstyleHandles.begin();
466 while (sitty!=drawstyleHandles.end()) {
467 vgDestroyPaint((VGPaint)(*sitty).second);
470 drawstyleHandles.clear();
474 int OsdOpenVG::shutdown()
478 #ifdef PICTURE_DECODER_OMX
479 if (imageomx) reader.removeDecoder(imageomx);
483 if (!initted) return 0;
486 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1");
488 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1a");
490 //(((VideoOMX*)Video::getInstance())->shutdownUsingOSDObjects());
491 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
493 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in shutdown %x", eglGetError());
496 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
498 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api thread failed! %x", eglGetError());
501 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark2");
502 processOpenVGCommands();
503 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark3");
508 //purgeAllReferences();
510 vgDestroyFont(vgfont);
511 vgDestroyFont(vgttfont);
512 vgDestroyPaint(vgttpaint);
514 float colclear[] = {0.8f, 0.8f, 0.8f, 1.f};
515 vgSetfv(VG_CLEAR_COLOR, 4, colclear);
516 vgClear(0, 0, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT);
517 eglSwapBuffers(egl_display, egl_surface);
518 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out final");
519 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
521 if (eglDestroySurface(egl_display, egl_surface) == EGL_FALSE)
523 Log::getInstance()->log("OSD", Log::ERR, "eglDestroySurface failed %x", eglGetError());
526 if (eglDestroyContext(egl_display, egl_context) == EGL_FALSE)
528 Log::getInstance()->log("OSD", Log::ERR, "eglDestroyContext failed %x", eglGetError());
531 if (eglTerminate(egl_display ) == EGL_FALSE)
533 Log::getInstance()->log("OSD", Log::ERR, "eglTerminate failed %x", eglGetError());
536 DISPMANX_UPDATE_HANDLE_T bcm_update;
537 bcm_update = vc_dispmanx_update_start(0);
539 vc_dispmanx_element_remove(bcm_update, bcm_element);
540 vc_dispmanx_element_remove(bcm_update, bcm_background);
541 vc_dispmanx_update_submit_sync(bcm_update);
542 vc_dispmanx_resource_delete(bcm_backres);
544 vc_dispmanx_display_close(bcm_display);
548 void OsdOpenVG::threadMethod()
550 // We have to claim the egl context for this thread
551 Log::getInstance()->log("OSD", Log::NOTICE, "Entering drawing thread");
553 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
555 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in thread %x", eglGetError());
559 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
561 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api thread failed! %x", eglGetError());
573 long long time1 = getTimeMS();
575 if ((time1 - lastrendertime) > 200) //5 fps for OSD updates are enough, avoids tearing
582 lastrendertime = getTimeMS();
588 ts = time1 - lastrendertime;
591 if (processOpenVGCommands()) ts = 0;
594 if (!threadIsActive())
596 if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ) == EGL_FALSE)
598 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current out thread failed");
606 struct timespec target_time;
607 clock_gettime(CLOCK_REALTIME, &target_time);
608 target_time.tv_nsec += 1000000LL * ts;
610 if (target_time.tv_nsec > 999999999)
612 target_time.tv_nsec -= 1000000000L;
613 target_time.tv_sec += 1;
617 threadWaitForSignalTimed(&target_time);
622 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
625 void OsdOpenVG::InternalRendering()
628 Colour bg = DrawStyle::WALLPAPER;
629 float colclear[] = {1.f, 1.0f, 1.f, 1.f};
631 if (bg.alpha == 0) colclear[3] = 0.f;
633 vgSetfv(VG_CLEAR_COLOR, 4, colclear);
634 vgClear(0, 0, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT);
635 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
637 drawSurfaces(); //iterate through and draws all commands
639 //Show it to the user!
640 eglSwapBuffers(egl_display, egl_surface);
646 float OsdOpenVG::getFontHeight()
648 return font_height; //dummy
651 float OsdOpenVG::getCharWidth(wchar_t c)
653 if (c < 256) return byte_char_width[c];
655 unsigned int glyph_index = FT_Get_Char_Index(ft_face, c);
656 return font_exp_x[glyph_index];
659 unsigned int OsdOpenVG::loadTTchar(cTeletextChar c)
661 unsigned int glyph_index = c.getGlyphIndex();
663 if (tt_font_chars.find(glyph_index) != tt_font_chars.end())
668 unsigned int buffer[10];
669 const VGfloat glyphOrigin[] = { 0.f, 0.f };
670 const VGfloat escapement[] = { 12.f, 0.f };
671 unsigned int* charmap = GetFontChar(c, buffer);
673 if (!charmap) return 0; //invalid char
675 for (int i = 0; i < 10; i++)
677 buffer[i] = charmap[i] >> 4;
680 VGImage handle = vgCreateImage(
684 VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER
685 | VG_IMAGE_QUALITY_BETTER);
686 vgImageSubData(handle, buffer, 4, VG_A_1, 0, 0, 12, 10);
690 handle, const_cast<VGfloat*>(glyphOrigin), const_cast<VGfloat*>(escapement));
691 vgDestroyImage(handle);
692 tt_font_chars[glyph_index] = 1;
697 int OsdOpenVG::getFontNames(const char*** names, const char*** names_keys)
699 *names = const_cast<const char**>(&(fontnames[0]));
700 *names_keys = const_cast<const char**>(&(fontnames_keys[0]));
701 return fontnames.size();
704 void OsdOpenVG::setFont(const char* fontname)
706 if (strcmp(fontname, cur_fontname))
709 if (cur_fontname) free(cur_fontname);
711 cur_fontname = static_cast<char*>(malloc(strlen(fontname) + 1));
712 strcpy(cur_fontname, fontname);
714 struct OpenVGCommand comm;
715 comm.task = OVGreplacefont;
716 putOpenVGCommand(comm, false);
720 int OsdOpenVG::loadFont(bool newfont)
723 float font_size = 16.f;
725 if (!freetype_inited)
727 error = FT_Init_FreeType(&ft_library);
731 Log::getInstance()->log("OSD", Log::WARN, "Could not load freetype %x", error);
736 if (!freetype_inited || newfont)
738 //first get the filename algorith extracted from vdr by Klaus Schmidinger
740 FcPattern* pattern = FcNameParse(reinterpret_cast<FcChar8*>(cur_fontname));
741 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
742 FcConfigSubstitute(NULL, pattern, FcMatchPattern);
743 FcDefaultSubstitute(pattern);
745 FcFontSet* fonts = FcFontSort(NULL, pattern, FcFalse, NULL, &fres);
746 FcChar8* filename = NULL;
750 for (int i = 0; i < fonts->nfont; i++)
753 FcPatternGetBool(fonts->fonts[i], FC_SCALABLE, 0, &canscale);
757 FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &filename);
762 FcFontSetDestroy(fonts);
766 Log::getInstance()->log("OSD", Log::CRIT, "Could not locate a font! Abort!");
770 FcPatternDestroy(pattern);
772 Log::getInstance()->log("OSD", Log::NOTICE, "Load Font %s: %s", cur_fontname, filename);
773 // second load the font
775 error = FT_New_Face(ft_library, reinterpret_cast<const char*>(filename), 0, &new_ft_face);
779 Log::getInstance()->log("OSD", Log::WARN, "Could not load font face %x %s", error, filename);
783 error = FT_Set_Char_Size(new_ft_face, 0, font_size * 256, 0, 0 /*dpi*/);
787 FT_Done_Face(new_ft_face);
788 Log::getInstance()->log("OSD", Log::WARN, "Could not set face size %x", error);
792 FT_Face old_ft_face = ft_face; // do it thread safe
793 ft_face = new_ft_face;
795 if (freetype_inited) FT_Done_Face(old_ft_face);//
797 freetype_inited = true;
800 vgfont = vgCreateFont(0);
803 font_height = ft_face->size->metrics.height / 256.f;
804 cur_char = FT_Get_First_Char(ft_face, &glyph);
805 std::vector<VGubyte> segments;
806 std::vector<VGfloat> coord;
807 segments.reserve(256);
810 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph test %d %x %x %d",cur_char,font_data_end,font_data,glyph);
813 error = FT_Load_Glyph(ft_face, glyph, FT_LOAD_DEFAULT);
817 cur_char = FT_Get_Next_Char(ft_face, cur_char, &glyph);
818 Log::getInstance()->log("OSD", Log::WARN, "Could not load glyph %x %c", error);
823 FT_Outline ot = ft_face->glyph->outline;
827 if (ot.n_contours == 0)
829 path = VG_INVALID_HANDLE;
833 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
834 1.0f, 0.f, 0, 0, VG_PATH_CAPABILITY_ALL);
837 FT_Vector* pt = ot.points;
838 const char* tags = ot.tags;
839 const short* cont = ot.contours;
840 short n_cont = ot.n_contours;
842 //short n_point=ot.n_points;
844 for (short point = 0; n_cont != 0; cont++, n_cont--)
846 short next_cont = *cont + 1;
849 short first_point = point;
851 //Log::getInstance()->log("OSD", Log::DEBUG, "runs %d",*cont);
852 for (; point < next_cont; point++)
854 char tag = tags[point];
855 FT_Vector fpoint = pt[point];
857 // Log::getInstance()->log("OSD", Log::DEBUG, "tag %d point %d %d: %d %d",tag,fpoint.x,fpoint.y,point,n_point);
860 segments.push_back(VG_MOVE_TO);
863 else if (tag & 0x1) //on curve
867 segments.push_back(VG_LINE_TO);
869 else if (last_tag & 0x2)
871 segments.push_back(VG_CUBIC_TO);
875 segments.push_back(VG_QUAD_TO);
883 if (!(last_tag & 0x1))
885 segments.push_back(VG_QUAD_TO);
886 int coord_size = coord.size();
887 VGfloat x = (coord[coord_size - 2] + ((float)fpoint.x) / 256.f) * 0.5f * aspect_correction;
888 VGfloat y = (coord[coord_size - 1] + (font_size - ((float)fpoint.y) / 256.f)) * 0.5f;
896 coord.push_back(((float)fpoint.x)*aspect_correction / 256.);
897 coord.push_back(font_size - ((float)fpoint.y) / 256.);
898 //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]);
901 if (!(last_tag & 0x1))
905 segments.push_back(VG_CUBIC_TO);
909 segments.push_back(VG_QUAD_TO);
912 coord.push_back(((float)pt[first_point].x)*aspect_correction / 256.);
913 coord.push_back(font_size - ((float)pt[first_point].y) / 256.);
916 //segments.push_back(VG_CLOSE_PATH);
919 vgAppendPathData(path, segments.size(), &segments[0], &coord[0]);
920 /* for (int m=0;m<segments.size();m++) {
925 Log::getInstance()->log("OSD", Log::DEBUG, "Move To %g %g",coord[n],coord[n+1]);n+=2; break;
927 Log::getInstance()->log("OSD", Log::DEBUG, "Line To %g %g",coord[n],coord[n+1]);n+=2; break;
929 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;
931 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;
933 Log::getInstance()->log("OSD", Log::DEBUG, "Close Path"); break;
937 //vguRect(path,0.f,0.f,1.f,1.f);
938 //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph %d %x",segments.size(),vgGetError());
941 VGfloat ori[] = {0.f, 0.f};
942 VGfloat esp[] = {ft_face->glyph->advance.x / 256.f * aspect_correction, ft_face->glyph->advance.y / 256.f};
943 font_exp_x[glyph] = ft_face->glyph->advance.x / 256.f * aspect_correction; //recalculate
945 vgSetGlyphToPath(vgfont, glyph, path, VG_FALSE, ori, esp);
947 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph %d %d %x",path,glyph,vgGetError());
948 if (path != VG_INVALID_HANDLE)
953 cur_char = FT_Get_Next_Char(ft_face, cur_char, &glyph);
956 for (int i = 0; i < 256; i++)
958 unsigned int glyph_index = FT_Get_Char_Index(ft_face, i);
959 byte_char_width[i] = font_exp_x[glyph_index];
965 void OsdOpenVG::drawSetTrans(SurfaceInfo& sc)
967 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
969 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
970 vgTranslate(0.f + sc.x, -576.f + sc.y);
972 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
974 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
975 vgTranslate(0.f + sc.x, -576.f + sc.y);
977 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
979 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
980 vgTranslate(0.f + sc.x, -576.f + sc.y);
984 //vgTranslate(0.f+sc.x,576.f-sc.y);
985 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Translate %g %g",sc.x,sc.y);
988 void OsdOpenVG::executeDrawCommand(SVGCommand& command)
990 VGfloat save_matrix[9];
991 VGfloat save_matrix2[9];
993 switch (command.instr)
997 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
999 // rgba = vgGetColor((VGPaint) command.handle);
1000 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Path %d %x %g %g %g %g",command.handle,command.target.path_index,command.x,command.y,command.w,command.h);
1001 //vgSeti(VG_FILL_RULE,);
1003 vgGetMatrix(save_matrix);
1004 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1005 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1006 vgTranslate(command.x, command.y);
1007 vgScale(command.w, command.h);
1008 vgDrawPath(std_paths[command.target.path_index], VG_FILL_PATH);
1009 vgLoadMatrix(save_matrix);
1014 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
1015 vgGetMatrix(save_matrix);
1016 VGfloat imagewidth = vgGetParameteri((VGImage) command.target.image, VG_IMAGE_WIDTH);
1017 VGfloat imageheight = vgGetParameteri((VGImage) command.target.image, VG_IMAGE_HEIGHT);
1019 //vgScale(command.w,command.h);
1021 if (command.handle) //special behaviout for bw images they act as a mask on the current paint
1023 vgTranslate(command.x, command.y);
1024 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1025 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1026 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
1027 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1028 vgScale(aspect_correction, 1.f);
1029 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1030 vgGetMatrix(save_matrix2);
1031 vgScale(imagewidth, imageheight);
1035 //vgScale(720.f/((float)BACKBUFFER_WIDTH), 576.f/((float)BACKBUFFER_HEIGHT));
1036 float scalex = command.w / imagewidth;
1037 float scaley = command.h / imageheight;
1038 float tx = command.x;
1039 float ty = command.y;
1041 if (command.corner == TopLeftLimited)
1043 if (scalex != 0.f && scaley != 0.f)
1045 float imageaspect = imagewidth / imageheight;
1046 float boxaspect = command.w / command.h / aspect_correction;
1048 if (imageaspect > boxaspect)
1051 ty += (command.h - imageheight * scalex / aspect_correction) * 0.5f;
1056 tx += (command.w - imagewidth * scaley * aspect_correction) * 0.5f;
1061 if (scalex == 0.f && scaley == 0.f)
1063 scalex = aspect_correction;
1066 else if (scalex == 0.f)
1068 scalex = scaley * aspect_correction;
1070 else if (scaley == 0.f)
1072 scaley = scalex / aspect_correction;
1075 if (command.corner == BottomRight || command.corner == BottomLeft || command.corner == BottomMiddle)
1077 ty -= imageheight * scaley;
1080 if (command.corner == BottomRight || command.corner == TopRight)
1082 tx -= imagewidth * scalex;
1085 if (command.corner == BottomMiddle || command.corner == TopMiddle)
1087 tx -= imagewidth * scalex * 0.5f;
1090 vgTranslate(tx, ty);
1091 //vgScale(command.w/imagewidth,command.h/imageheight);
1092 vgScale(scalex, scaley);
1093 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1094 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1095 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia Draw Image Scale %g %g %g %g %g %g",command.w,imagewidth,command.h,imageheight,scalex,scaley);
1099 //vgTranslate(200.f,500.f);
1100 //vgScale(100.f,100.f);
1102 vgDrawImage(static_cast<VGImage>(command.target.image));
1104 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Image %d %x %g %g %g %g %x",command.handle,command.target.image,command.x,command.y,command.w,command.h,
1108 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1109 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1110 vgLoadMatrix(save_matrix2);
1113 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
1115 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
1116 vgLoadMatrix(save_matrix);
1121 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1122 vgGetMatrix(save_matrix);
1123 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1124 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1125 vgTranslate(command.x, command.y);
1126 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1127 vgGetMatrix(save_matrix2);
1128 unsigned int glyph_index = FT_Get_Char_Index(ft_face, command.target.textchar);
1129 vgScale(font_exp_x[glyph_index], font_height);
1131 VGfloat gori[] = {0., 0.};
1132 vgSetfv(VG_GLYPH_ORIGIN, 2, gori);
1134 vgDrawGlyph(vgfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1135 //vgDrawPath(std_paths[Rectangle],VG_FILL_PATH);
1136 /* Log::getInstance()->log("OSD", Log::DEBUG, "Draw Glyph %d %c %d %g %g %x",command.handle,command.target.textchar,glyph_index,command.x,command.y,
1138 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1139 vgLoadMatrix(save_matrix);
1140 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1141 vgLoadMatrix(save_matrix2);
1143 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1148 cTeletextChar tchar;
1149 tchar.setInternal(command.target.ttchar);
1150 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1151 vgGetMatrix(save_matrix);
1152 enumTeletextColor ttforegcolour = tchar.GetFGColor();
1153 enumTeletextColor ttbackgcolour = tchar.GetBGColor();
1155 if (tchar.GetBoxedOut())
1157 ttforegcolour = ttcTransparent;
1158 ttbackgcolour = ttcTransparent;
1161 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
1162 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1164 vgTranslate(command.x + command.w * 11.85f * 1.4f, command.y + command.h * 19.75f);
1165 VGfloat gori[] = {0., 0.};
1166 vgSetfv(VG_GLYPH_ORIGIN, 2, gori);
1168 vgScale(-1.4f, 2.f);
1169 unsigned int color = Surface::enumTeletextColorToCoulour(ttbackgcolour).rgba();
1170 color = color << 8 | (color & 0xff000000) >> 24;
1171 vgSetColor(vgttpaint, color);
1172 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_FILL_PATH);
1173 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_STROKE_PATH);
1174 cTeletextChar filled;
1175 filled.setInternal(0x187f);
1176 unsigned int glyph_index = loadTTchar(filled);
1177 vgDrawGlyph(vgttfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1179 color = Surface::enumTeletextColorToCoulour(ttforegcolour).rgba();
1180 color = color << 8 | (color & 0xff000000) >> 24;
1181 vgSetColor(vgttpaint, color);
1182 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_FILL_PATH);
1183 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_STROKE_PATH);
1184 glyph_index = loadTTchar(tchar);
1185 vgDrawGlyph(vgttfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1187 /* Log::getInstance()->log("OSD", Log::DEBUG, "Draw TTchar %x %x %x %x",glyph_index,ttforegcolour,Surface::enumTeletextColorToCoulour(ttforegcolour).rgba(),
1188 vgGetColor(vgttpaint));*/
1190 vgLoadMatrix(save_matrix);
1191 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1192 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1193 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
1198 VGint coords[4] = {0, 0, 0, 0};
1199 coords[0] = ((command.x + clip_shift_x) * ((float)BACKBUFFER_WIDTH) / 720.f);
1200 coords[1] = ((576.f - command.y - clip_shift_y - command.h) * ((float)BACKBUFFER_HEIGHT) / 576.f);
1201 coords[2] = ((command.w - 1.f) * ((float)BACKBUFFER_WIDTH) / 720.f);
1202 coords[3] = ((command.h - 1.f) * ((float)BACKBUFFER_HEIGHT) / 576.f);
1203 vgSetiv(VG_SCISSOR_RECTS, 4, coords);
1205 if (command.w == 0.f && command.h == 0.f)
1206 vgSeti(VG_SCISSORING, VG_FALSE);
1208 vgSeti(VG_SCISSORING, VG_TRUE);
1212 case DrawImageLoading:
1218 //int imcount=0;// this is debug code and should not go into release
1219 unsigned int OsdOpenVG::handleOpenVGCommand(OpenVGCommand& command)
1221 switch (command.task)
1223 case OVGreplacefont:
1225 vgDestroyFont(vgfont);
1229 case OVGdestroyImageRef: //imcount--;
1231 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia Draw Image Destroy %x %d",command.param1,imcount);
1232 vgDestroyImage(static_cast<VGImage>(command.param1));
1235 case OVGdestroyPaint:
1237 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint Destroy %d ",command.param1);
1238 vgDestroyPaint(static_cast<VGPaint>(command.param1));
1241 case OVGcreateImagePalette: //imcount++;
1243 VGImage input = vgCreateImage(VG_A_8, command.param1, command.param2,
1244 VG_IMAGE_QUALITY_NONANTIALIASED |
1245 VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER);
1246 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create palette %d %d %x %d",command.param1,command.param2,vgGetError(),input);
1247 vgImageSubData(input, command.data, command.param1,
1248 VG_A_8, 0, 0, command.param1, command.param2); // upload palettized image data
1249 VGImage handle = vgCreateImage(VG_sRGBA_8888, command.param1, command.param2,
1250 VG_IMAGE_QUALITY_NONANTIALIASED |
1251 VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER);
1252 VGuint* palette = static_cast<VGuint*>(malloc(256 * sizeof(VGuint)));
1253 const VGuint* in_palette = static_cast<const VGuint*>(command.data2);
1255 for (int i = 0; i < 256; i++)
1257 VGuint color = in_palette[i];
1258 palette[i] = color << 8 | (color & 0xff000000) >> 24;
1261 vgLookupSingle(handle, input, palette, VG_ALPHA, VG_FALSE, VG_FALSE);
1263 vgDestroyImage(input);
1267 case OVGcreateMonoBitmap: //imcount++;
1269 VGImage handle = vgCreateImage(VG_A_1, command.param1, command.param2,
1270 VG_IMAGE_QUALITY_FASTER);
1271 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1272 unsigned int buffer_len = (command.param1 * command.param2) >> 3;
1273 unsigned char* buffer = static_cast<unsigned char*>(malloc(buffer_len));
1274 unsigned char* r_buffer1 = buffer;
1275 const unsigned char* r_buffer2 = static_cast<const unsigned char*>(command.data);
1276 unsigned char* buffer_end = buffer + buffer_len;
1278 while (r_buffer1 != buffer_end)
1280 unsigned char byte = *r_buffer2;
1281 *r_buffer1 = ((byte * 0x0802LU & 0x22110LU) | (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
1282 r_buffer1++; r_buffer2++;
1285 vgImageSubData(handle, buffer, command.param1 >> 3, VG_A_1, 0, 0, command.param1, command.param2);
1287 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono2 %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1290 /*case OVGcreateImageFile: {
1293 Image *imagefile=(Image*)command.data;
1295 imagefile->write(&imageblob,"RGBA");
1297 handle=vgCreateImage(VG_sXBGR_8888,imagefile->columns(),imagefile->rows(),
1298 VG_IMAGE_QUALITY_BETTER);
1299 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark1",imagefile->columns(),imagefile->rows(),(unsigned int*)imageblob.data());
1300 vgImageSubData(handle,imageblob.data(),imagefile->columns()*4,
1301 VG_sXBGR_8888,0,0,imagefile->columns(),imagefile->rows());
1302 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark2",imagefile->columns(),imagefile->rows(),(unsigned int*)imageblob.data());
1304 }catch( Exception &error_ )
1306 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick hT: %s",error_.what());
1311 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create file %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1314 case OVGcreateImageMemory: //imcount++;
1316 const PictureInfo* info = static_cast<const PictureInfo*>(command.data);
1318 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateImageMemory %d",imcount);
1319 handle = vgCreateImage(VG_sABGR_8888, info->width, info->height, VG_IMAGE_QUALITY_BETTER);
1320 vgImageSubData(handle, info->image, info->width * 4,
1321 VG_sABGR_8888, 0, 0, info->width, info->height);
1322 info->decoder->freeReference(info->reference);
1324 bool static_image = true;
1326 if (info->lindex & 0xffffffff) static_image = false;
1328 Message* m = new Message();
1329 // We have a pictures! send a message to ourself, to switch to gui thread
1331 m->p_to = Message::CONTROL;
1332 m->data = reinterpret_cast<void*>(handle);
1336 m->message = Message::NEW_PICTURE;
1337 m->tag = info->lindex;
1341 m->message = Message::NEW_PICTURE_STATIC;
1342 m->tag = info->lindex >> 32LL;
1345 MessageQueue::getInstance()->postMessage(m); // inform control about new picture
1350 case OVGcreateEGLImage: //imcount++;
1352 PictureInfo* info = const_cast<PictureInfo*>(static_cast<const PictureInfo*>(command.data));
1355 handle = vgCreateImage(VG_sABGR_8888, info->width, info->height, VG_IMAGE_QUALITY_BETTER);
1356 // Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateEGLImage %d %d %x %d",info->width,info->height, handle,imcount);
1358 info->handle = handle;
1359 info->reference = eglCreateImageKHR(egl_display, egl_context, EGL_VG_PARENT_IMAGE_KHR, reinterpret_cast<EGLClientBuffer>(handle), NULL);
1360 if (info->reference) return true;
1362 Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateEGLImage %d %d %x Fail!", info->width, info->height, handle);
1363 if (handle) vgDestroyImage(handle);
1366 case OVGreadyEGLImage:
1368 PictureInfo* info = const_cast<PictureInfo*>(static_cast<const PictureInfo*>(command.data));
1369 eglDestroyImageKHR(egl_display, info->reference);
1370 bool static_image = true;
1372 if (info->lindex & 0xffffffff) static_image = false;
1374 Message* m = new Message();
1376 m->p_to = Message::CONTROL;
1377 m->data = reinterpret_cast<void*>(info->handle);
1381 m->message = Message::NEW_PICTURE;
1382 m->tag = info->lindex;
1386 m->message = Message::NEW_PICTURE_STATIC;
1387 m->tag = info->lindex >> 32LL;
1390 MessageQueue::getInstance()->postMessage(m); // inform command about new picture
1395 case OVGcreateColorRef:
1398 handle = vgCreatePaint();
1399 const DrawStyle* style = static_cast<const DrawStyle*>(command.data);
1403 case DrawStyle::Color:
1405 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
1406 vgSetColor(handle, command.param1);
1408 //rgba = vgGetColor((VGPaint)handle);
1409 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint %d %x %x",handle,command.param1,rgba);
1412 case DrawStyle::GradientLinear:
1414 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
1415 VGfloat params[] = {style->x1, style->y1, style->x2, style->y2, style->r};
1416 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Gradient %d %g %g %g %g",handle,params[0],params[1],params[2],params[3]);
1417 vgSetParameterfv(handle, VG_PAINT_LINEAR_GRADIENT, 4, params);
1420 case DrawStyle::GradientRadial:
1422 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
1423 VGfloat params[] = {style->x1, style->y1, style->x2, style->y2, style->r};
1424 vgSetParameterfv(handle, VG_PAINT_RADIAL_GRADIENT, 5, params);
1429 if (style->ft == DrawStyle::GradientLinear || style->ft == DrawStyle::GradientRadial)
1431 VGfloat colorramp[5 * 5];
1432 colorramp[0 + 0 * 5] = 0.f;
1433 colorramp[1 + 0 * 5] = style->red / 255.f;
1434 colorramp[2 + 0 * 5] = style->green / 255.f;
1435 colorramp[3 + 0 * 5] = style->blue / 255.f;
1436 colorramp[4 + 0 * 5] = style->alpha / 255.f;
1438 for (int i = 0; i < (style->num_colors - 1); i++)
1440 colorramp[0 + (i + 1) * 5] = style->grad_pos[i];
1441 colorramp[1 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].red) / 255.f;
1442 colorramp[2 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].green) / 255.f;
1443 colorramp[3 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].blue) / 255.f;
1444 colorramp[4 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].alpha) / 255.f;
1447 colorramp[0 + (style->num_colors) * 5] = 1.f;
1448 colorramp[1 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].red) / 255.f;
1449 colorramp[2 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].green) / 255.f;
1450 colorramp[3 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].blue) / 255.f;
1451 colorramp[4 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].alpha) / 255.f;
1452 vgSetParameteri(handle, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_REFLECT);
1453 vgSetParameteri(handle, VG_PAINT_COLOR_RAMP_PREMULTIPLIED, VG_FALSE);
1454 vgSetParameterfv(handle, VG_PAINT_COLOR_RAMP_STOPS, 5 + (style->num_colors) * 5, colorramp);
1460 case OVGimageUploadLine:
1467 bool OsdOpenVG::processOpenVGCommands()
1469 bool worked = false;
1473 while (vgcommands.size() > 0)
1475 OpenVGCommand comm = vgcommands.front();
1476 vgcommands.pop_front();
1479 OpenVGResponse resp;
1480 resp.result = handleOpenVGCommand(comm);
1486 vgresponses.push_back(resp);
1492 /* Getting rid of Signal class. As with VideoOMX, just replicate what Signal did here
1493 * and figure out if any of this can be simplified later. e.g. taskmutex sounds
1494 * like it should be the mutex being used. 3 mutexes here???
1497 vgTaskSignalMutex.lock();
1498 vgTaskSignal.notify_one();
1499 vgTaskSignalMutex.unlock();
1512 unsigned int OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm, bool wait)
1517 comm.id = wait_id++;
1519 comm.id = 0; // we are not waiting
1521 vgcommands.push_back(comm);
1526 if (!wait) return 0;
1530 // Is there a response now?
1532 for (auto& vgresponse : vgresponses)
1534 if (vgresponse.id == comm.id)
1536 UINT resp = vgresponse.result;
1544 std::unique_lock<std::mutex> ul(vgTaskSignalMutex);
1545 vgTaskSignal.wait_for(ul, std::chrono::milliseconds(100));
1550 void OsdOpenVG::destroyImageRef(ImageIndex index)
1552 struct OpenVGCommand comm;
1553 comm.task = OVGdestroyImageRef;
1554 comm.param1 = index;
1555 putOpenVGCommand(comm, false);
1558 bool OsdOpenVG::getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length)
1560 if (sa_MAX > static_id)
1562 *userdata = static_artwork_begin[static_id];
1563 *length = static_artwork_end[static_id] - static_artwork_begin[static_id];
1572 void OsdOpenVG::createPicture(struct PictureInfo& pict_inf)
1574 struct OpenVGCommand comm;
1575 Log::getInstance()->log("OsdOpenVG", Log::DEBUG, "TVMedia Create Picture %d", pict_inf.type);
1577 if (pict_inf.type == PictureInfo::RGBAMemBlock)
1579 comm.task = OVGcreateImageMemory;
1580 comm.data = new PictureInfo(pict_inf);
1581 putOpenVGCommand(comm, false);
1583 else if (pict_inf.type == PictureInfo::EGLImage)
1585 comm.task = OVGreadyEGLImage;
1586 comm.data = new PictureInfo(pict_inf);
1587 putOpenVGCommand(comm, false);
1592 pict_inf.decoder->freeReference(pict_inf.reference);
1596 bool OsdOpenVG::getEGLPicture(struct OsdVector::PictureInfo& info, EGLDisplay* display)
1598 struct OpenVGCommand comm;
1599 info.type = PictureInfo::EGLImage;
1600 comm.task = OVGcreateEGLImage;
1602 *display = egl_display;
1603 return putOpenVGCommand(comm, true);
1606 ImageIndex OsdOpenVG::createMonoBitmap(void* base, int width, int height)
1608 struct OpenVGCommand comm;
1609 comm.task = OVGcreateMonoBitmap;
1610 comm.param1 = width;
1611 comm.param2 = height;
1613 return putOpenVGCommand(comm, true);
1616 ImageIndex OsdOpenVG::createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data)
1618 struct OpenVGCommand comm;
1619 comm.task = OVGcreateImagePalette;
1620 comm.param1 = width;
1621 comm.param2 = height;
1622 comm.data = image_data;
1623 comm.data2 = palette_data;
1624 return putOpenVGCommand(comm, true);
1627 void OsdOpenVG::destroyDrawStyleHandle(VectorHandle index)
1629 struct OpenVGCommand comm;
1630 comm.task = OVGdestroyPaint;
1631 comm.param1 = index;
1632 putOpenVGCommand(comm, false);
1635 VectorHandle OsdOpenVG::createDrawStyleHandle(const DrawStyle& c)
1637 unsigned int col = c.rgba();
1638 struct OpenVGCommand comm;
1639 comm.task = OVGcreateColorRef;
1640 comm.param1 = col << 8 | (col & 0xff000000) >> 24;
1642 return putOpenVGCommand(comm, true);