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/>.
21 #include <sys/syscall.h>
22 #include <fontconfig/fontconfig.h>
29 #include "messagequeue.h"
30 #include "teletxt/txtfont.h"
32 #include "osdopenvg.h"
34 #define EXTERNALPICTURE(name, fname, fileextension) extern uint8_t name ## _data[] asm("_binary_other_"#fname"_"#fileextension"_start"); \
35 extern uint8_t name ## _data_end[] asm("_binary_other_"#fname"_"#fileextension"_end");
39 #undef EXTERNALPICTURE
41 #define BACKBUFFER_WIDTH 1280
42 #define BACKBUFFER_HEIGHT 720
44 OsdOpenVG::OsdOpenVG()
48 lastrendertime = getTimeMS();
50 const char* fontname = "Droid Sans:style=Regular";
51 cur_fontname = static_cast<char*>(malloc(strlen(fontname) + 1));
52 strcpy(cur_fontname, fontname);
54 #define EXTERNALPICTURE(name, fname, fileextension) static_artwork_begin[sa_ ## name]=name ## _data;
58 #undef EXTERNALPICTURE
59 #define EXTERNALPICTURE(name, fname, fileextension) static_artwork_end[sa_ ## name]=name ## _data_end;
63 #undef EXTERNALPICTURE
66 OsdOpenVG::~OsdOpenVG()
68 if (initted) shutdown();
70 if (cur_fontname) free(cur_fontname);
72 if (freetype_inited) FT_Done_Face(ft_face);
74 for (char* c : fontnames) free(c);
75 for (char* c : fontnames_keys) free(c);
83 if (initted) return 0;
87 //First get connection to egl
88 egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
89 if (egl_display == EGL_NO_DISPLAY)
91 Log::getInstance()->log("OSD", Log::WARN, "Could not get egl display! %x", eglGetError());
96 if (eglInitialize(egl_display, NULL, NULL) == EGL_FALSE)
98 Log::getInstance()->log("OSD", Log::WARN, "Initialising display failed! %x", eglGetError());
103 const char* query_str = eglQueryString(egl_display, EGL_CLIENT_APIS);
105 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
106 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", eglGetError());
108 query_str = eglQueryString(egl_display, EGL_EXTENSIONS);
110 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
111 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", eglGetError());
113 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
115 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api failed! %x", eglGetError());
120 const EGLint attributs[] =
122 EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
123 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
124 EGL_CONFORMANT, EGL_OPENVG_BIT,
126 }; // Here, we might have to select the resolution!
130 if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number) == EGL_FALSE)
132 Log::getInstance()->log("OSD", Log::WARN, "Choosing egl config failed! %x", eglGetError());
137 egl_context = eglCreateContext(egl_display, egl_ourconfig, NULL, NULL);
139 if (egl_context == EGL_NO_CONTEXT)
141 Log::getInstance()->log("OSD", Log::WARN, "Creating egl context failed! %x", eglGetError());
146 // warning broadcom specific, get display size!
147 display_width = display_height = 0;
149 if (graphics_get_display_size(0, &display_width, &display_height) < 0)
151 Log::getInstance()->log("OSD", Log::WARN, "Getting display size failed! (BCM API) ");
156 Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ", display_width, display_height);
157 VC_RECT_T dst_rect = {0, 0, (int32_t)display_width, (int32_t)display_height};
158 VC_RECT_T src_rect = {0, 0, BACKBUFFER_WIDTH << 16, BACKBUFFER_HEIGHT << 16};
159 VC_RECT_T src_rect_bg = {0, 0, 16 << 16, 16 << 16};
160 // VC_RECT_T src_rect_im={0,0,16,16};
162 uint32_t back_image_ptr;
163 bcm_backres = vc_dispmanx_resource_create(VC_IMAGE_RGBX32, 16, 16, &back_image_ptr);
165 updateBackgroundColor(DrawStyle::WALLPAPER);
167 DISPMANX_UPDATE_HANDLE_T bcm_update;
168 bcm_display = vc_dispmanx_display_open(0);
169 bcm_update = vc_dispmanx_update_start(0);
170 bcm_element = vc_dispmanx_element_add(bcm_update, bcm_display,
172 &src_rect, DISPMANX_PROTECTION_NONE, 0, 0, (DISPMANX_TRANSFORM_T) 0);
175 bcm_background = vc_dispmanx_element_add(bcm_update, bcm_display,
176 0, &dst_rect, bcm_backres,
177 &src_rect_bg, DISPMANX_PROTECTION_NONE, 0, 0, (DISPMANX_TRANSFORM_T) 0);
179 vc_dispmanx_update_submit_sync(bcm_update);
181 static EGL_DISPMANX_WINDOW_T nativewindow;
182 nativewindow.element = bcm_element;
183 nativewindow.height = BACKBUFFER_HEIGHT;
184 nativewindow.width = BACKBUFFER_WIDTH;
186 egl_surface = eglCreateWindowSurface(egl_display, egl_ourconfig, &nativewindow, NULL);
187 if (egl_surface == EGL_NO_SURFACE)
189 Log::getInstance()->log("OSD", Log::WARN, "Creating egl window surface failed!");
194 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current in1%d", syscall(SYS_gettid));
196 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
198 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed");
205 query_str = reinterpret_cast<const char*>(vgGetString(VG_VERSION));
207 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
208 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", vgGetError());
210 query_str = reinterpret_cast<const char*>(vgGetString(VG_VENDOR));
212 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
213 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", vgGetError());
215 query_str = reinterpret_cast<const char*>(vgGetString(VG_RENDERER));
217 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
218 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", vgGetError());
220 query_str = reinterpret_cast<const char*>(vgGetString(VG_EXTENSIONS));
222 if (query_str) Log::getInstance()->logLongString("OSD", Log::NOTICE, query_str);
223 else Log::getInstance()->log("OSD", Log::WARN, "Could not query display %x", vgGetError());
225 aspect_correction = ((float)BACKBUFFER_HEIGHT) / 576.f / (((float)BACKBUFFER_WIDTH) / 720.f);
228 if (!fontnames.size())
230 //inspired by and copied from vdr's code
232 FcObjectSet* objset = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
233 FcPattern* pattern = FcPatternCreate();
234 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
235 FcFontSet* fonts = FcFontList(NULL, pattern, objset);
237 for (int i = 0; i < fonts->nfont; i++)
239 char* s = (char*)FcNameUnparse(fonts->fonts[i]);
243 char* c = strchr(s, ':');
247 char* s2 = strchr(c + 1, ',');
252 char* p = strchr(s, ',');
257 else memmove(p, c, strlen(c) + 1);
260 char* key = (char*)malloc(strlen(s) + 1);
262 fontnames_keys.push_back(key);
263 char* s2 = strstr(s, "style=");
267 memmove(s2, s2 + 6, strlen(s2 + 6) + 1);
270 fontnames.push_back(s);
274 FcFontSetDestroy(fonts);
275 FcPatternDestroy(pattern);
276 FcObjectSetDestroy(objset);
279 if (!loadFont(false))
284 vgttfont = vgCreateFont(0);
285 vgttpaint = vgCreatePaint();
286 vgSetParameteri( vgttpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
287 vgSetColor(vgttpaint, 0xffffffff);
289 eglSwapInterval(egl_display, 1);
291 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out 1%d", syscall(SYS_gettid));
292 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
293 //Now we will create the Screen
294 initted = true; // must set this here or create surface won't work
296 /*if (((VideoOMX*)Video::getInstance())->initUsingOSDObjects()!=1) { //call Video for init stuff
304 #ifdef PICTURE_DECODER_OMX
305 imageomx = new ImageOMX(&reader);
306 reader.addDecoder(imageomx);
312 int OsdOpenVG::stopUpdate()
315 processOpenVGCommands();
319 int OsdOpenVG::shutdown()
323 #ifdef PICTURE_DECODER_OMX
324 if (imageomx) reader.removeDecoder(imageomx);
328 if (!initted) return 0;
331 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1");
333 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark1a");
335 //(((VideoOMX*)Video::getInstance())->shutdownUsingOSDObjects());
336 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
338 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in shutdown %x", eglGetError());
341 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
343 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api thread failed! %x", eglGetError());
346 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark2");
347 processOpenVGCommands();
348 Log::getInstance()->log("OSD", Log::DEBUG, "shutdown mark3");
353 //purgeAllReferences();
355 vgDestroyFont(vgfont);
356 vgDestroyFont(vgttfont);
357 vgDestroyPaint(vgttpaint);
359 float colclear[] = {0.8f, 0.8f, 0.8f, 1.f};
360 vgSetfv(VG_CLEAR_COLOR, 4, colclear);
361 vgClear(0, 0, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT);
362 eglSwapBuffers(egl_display, egl_surface);
363 Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out final");
364 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
366 if (eglDestroySurface(egl_display, egl_surface) == EGL_FALSE)
368 Log::getInstance()->log("OSD", Log::ERR, "eglDestroySurface failed %x", eglGetError());
371 if (eglDestroyContext(egl_display, egl_context) == EGL_FALSE)
373 Log::getInstance()->log("OSD", Log::ERR, "eglDestroyContext failed %x", eglGetError());
376 if (eglTerminate(egl_display) == EGL_FALSE)
378 Log::getInstance()->log("OSD", Log::ERR, "eglTerminate failed %x", eglGetError());
381 DISPMANX_UPDATE_HANDLE_T bcm_update;
382 bcm_update = vc_dispmanx_update_start(0);
384 vc_dispmanx_element_remove(bcm_update, bcm_element);
385 vc_dispmanx_element_remove(bcm_update, bcm_background);
386 vc_dispmanx_update_submit_sync(bcm_update);
387 vc_dispmanx_resource_delete(bcm_backres);
389 vc_dispmanx_display_close(bcm_display);
393 void OsdOpenVG::threadMethod()
395 // We have to claim the egl context for this thread
396 Log::getInstance()->log("OSD", Log::NOTICE, "Entering drawing thread");
398 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
400 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current failed in thread %x", eglGetError());
404 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
406 Log::getInstance()->log("OSD", Log::WARN, "Binding openvg api thread failed! %x", eglGetError());
418 long long time1 = getTimeMS();
420 if ((time1 - lastrendertime) > 200) //5 fps for OSD updates are enough, avoids tearing
427 lastrendertime = getTimeMS();
433 ts = time1 - lastrendertime;
436 if (processOpenVGCommands()) ts = 0;
439 if (!threadIsActive())
441 if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) == EGL_FALSE)
443 Log::getInstance()->log("OSD", Log::WARN, "Making egl Current out thread failed");
451 struct timespec target_time;
452 clock_gettime(CLOCK_REALTIME, &target_time);
453 target_time.tv_nsec += 1000000LL * ts;
455 if (target_time.tv_nsec > 999999999)
457 target_time.tv_nsec -= 1000000000L;
458 target_time.tv_sec += 1;
462 threadWaitForSignalTimed(&target_time);
467 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
470 UINT OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm, bool wait)
472 if (wait) comm.response = new OpenVGResponse;
474 std::unique_lock<std::mutex> ul(taskmutex); // locks
475 vgcommands.push_back(comm);
478 threadSignal(); // signal renderLoop
483 // Wait until done is true and we are signalled. If done is already true, this returns immediately
484 comm.response->doneCond.wait(ul, [&comm]{ return comm.response->done; });
486 // Now response->done = true, mutex is locked, we have been signalled
489 UINT toReturn = comm.response->result;
490 delete comm.response;
494 bool OsdOpenVG::processOpenVGCommands()
499 while (vgcommands.size() > 0)
503 OpenVGCommand comm = vgcommands.front();
504 vgcommands.pop_front();
508 UINT vgResult = handleOpenVGCommand(comm);
512 if (comm.response) // There is a response object, a thread is waiting
514 comm.response->result = vgResult;
515 comm.response->done = true;
516 comm.response->doneCond.notify_one();
524 void OsdOpenVG::InternalRendering()
527 Colour bg = DrawStyle::WALLPAPER;
528 float colclear[] = {1.f, 1.0f, 1.f, 1.f};
530 if (bg.alpha == 0) colclear[3] = 0.f;
532 vgSetfv(VG_CLEAR_COLOR, 4, colclear);
533 vgClear(0, 0, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT);
534 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
536 drawSurfaces(); //iterate through and draws all commands
538 //Show it to the user!
539 eglSwapBuffers(egl_display, egl_surface);
543 // --------------------------------------------------------------------------------------------------------------------------
546 void OsdOpenVG::purgeAllReferences()
549 drawstyleHandlesRefCounts.clear(); // remove all references
552 map<void *,ImageIndex>::iterator mitty=monobitmaps.begin();
553 while (mitty!=monobitmaps.end()) {
554 vgDestroyImage((VGImage)(*mitty).second);
559 / *map<string,ImageIndex>::iterator jitty=jpegs.begin();
560 while (jitty!=jpegs.end()) {
561 vgDestroyImage((VGImage)(*jitty).second);
566 map<TVMediaInfo,ImageIndex>::iterator titty=tvmedias.begin();
567 while (titty!=tvmedias.end()) {
568 vgDestroyImage((VGImage)(*titty).second);
573 map<pair<Colour*,unsigned int>,unsigned int>::iterator sitty=drawstyleHandles.begin();
574 while (sitty!=drawstyleHandles.end()) {
575 vgDestroyPaint((VGPaint)(*sitty).second);
578 drawstyleHandles.clear();
582 void OsdOpenVG::updateBackgroundColor(DrawStyle bg)
584 unsigned int color[16 * 16];
586 if (!bcm_backres) return;
588 VC_RECT_T src_rect_im = {0, 0, 16, 16};
590 if (bg.ft != DrawStyle::GradientLinear)
595 //memset(color,0xFF,sizeof(unsigned int)*4*8);
596 for (int j = 0; j < 16; j++)
598 int helpr = (((15 - j) * bg.red) + (j * bg.grad_col[0].red)) / 15;
599 int helpb = (((15 - j) * bg.blue) + (j * bg.grad_col[0].blue)) / 15;
600 int helpg = (((15 - j) * bg.green) + (j * bg.grad_col[0].green)) / 15;
601 //unsigned int cur_col=help | (help<< 8) | (help<< 16) | (0xFF<< 24);
602 unsigned int cur_col = helpr | (helpg << (8)) | (helpb << (16)) | (0xFF << (24));
604 for (int i = 0; i < 16; i++)
606 color[i + 16 * j] = cur_col;
610 vc_dispmanx_resource_write_data(bcm_backres, VC_IMAGE_RGBX32, 16 * 4, color, &src_rect_im);
613 void OsdOpenVG::getScreenSize(int& width, int& height)
615 width = BACKBUFFER_WIDTH;
616 height = BACKBUFFER_HEIGHT;
619 void OsdOpenVG::getRealScreenSize(int& width, int& height)
621 width = display_width;
622 height = display_height;
625 bool OsdOpenVG::screenShot(void* buffer, int width, int height, bool osd /*include osd*/)
627 if (!initted) return false;
629 if (!buffer) return false;
631 DISPMANX_RESOURCE_HANDLE_T res;
632 DISPMANX_DISPLAY_HANDLE_T display;
636 res = vc_dispmanx_resource_create(VC_IMAGE_RGBA32, width, height, &image_ptr);
637 display = vc_dispmanx_display_open(0);
641 vc_dispmanx_snapshot(display, res,
642 static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_NO_RGB | DISPMANX_SNAPSHOT_FILL/*|DISPMANX_SNAPSHOT_PACK*/));
646 vc_dispmanx_snapshot(display, res,
647 static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_FILL));
650 vc_dispmanx_rect_set(&rect, 0, 0, width, height);
651 vc_dispmanx_resource_read_data(res, &rect, buffer, width * 4);
652 vc_dispmanx_resource_delete(res);
653 vc_dispmanx_display_close(display);
657 void OsdOpenVG::initPaths()
660 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
661 VG_PATH_DATATYPE_F, 1.f, 0.f,
662 0, 0, VG_PATH_CAPABILITY_ALL);
664 vguLine(current, 0.f, 0.f, 1.f, 0.f);
666 std_paths[PIHorzLine] = current;
668 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
669 VG_PATH_DATATYPE_F, 1.f, 0.f,
670 0, 0, VG_PATH_CAPABILITY_ALL);
671 vguLine(current, 0.f, 0.f, 0.f, 1.f);
673 std_paths[PIVertLine] = current;
675 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
676 VG_PATH_DATATYPE_F, 1.f, 0.f,
677 0, 0, VG_PATH_CAPABILITY_ALL);
678 //vguRect(current,0.f,0.f,1.f,1.f);
679 vguRect(current, 0.f, 0.f, 1.f, 1.f);
681 std_paths[PIRectangle] = current;
683 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
684 VG_PATH_DATATYPE_F, 1.f, 0.f,
686 vguEllipse(current, 0.f, 0.f, 1.f, 1.f);
688 std_paths[PIPoint] = current;
691 void OsdOpenVG::destroyPaths()
693 vgDestroyPath(std_paths[PIHorzLine]);
694 vgDestroyPath(std_paths[PIVertLine]);
695 vgDestroyPath(std_paths[PIRectangle]);
696 vgDestroyPath(std_paths[PIPoint]);
701 float OsdOpenVG::getFontHeight()
703 return font_height; //dummy
706 float OsdOpenVG::getCharWidth(wchar_t c)
708 if (c < 256) return byte_char_width[c];
710 unsigned int glyph_index = FT_Get_Char_Index(ft_face, c);
711 return font_exp_x[glyph_index];
714 unsigned int OsdOpenVG::loadTTchar(cTeletextChar c)
716 unsigned int glyph_index = c.getGlyphIndex();
718 if (tt_font_chars.find(glyph_index) != tt_font_chars.end())
723 unsigned int buffer[10];
724 const VGfloat glyphOrigin[] = { 0.f, 0.f };
725 const VGfloat escapement[] = { 12.f, 0.f };
726 unsigned int* charmap = GetFontChar(c, buffer);
728 if (!charmap) return 0; //invalid char
730 for (int i = 0; i < 10; i++)
732 buffer[i] = charmap[i] >> 4;
735 VGImage handle = vgCreateImage(
739 VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER
740 | VG_IMAGE_QUALITY_BETTER);
741 vgImageSubData(handle, buffer, 4, VG_A_1, 0, 0, 12, 10);
745 handle, const_cast<VGfloat*>(glyphOrigin), const_cast<VGfloat*>(escapement));
746 vgDestroyImage(handle);
747 tt_font_chars[glyph_index] = 1;
752 int OsdOpenVG::getFontNames(const char*** names, const char*** names_keys)
754 *names = const_cast<const char**>(&(fontnames[0]));
755 *names_keys = const_cast<const char**>(&(fontnames_keys[0]));
756 return fontnames.size();
759 void OsdOpenVG::setFont(const char* fontname)
761 if (strcmp(fontname, cur_fontname))
764 if (cur_fontname) free(cur_fontname);
766 cur_fontname = static_cast<char*>(malloc(strlen(fontname) + 1));
767 strcpy(cur_fontname, fontname);
769 struct OpenVGCommand comm;
770 comm.task = OVGreplacefont;
771 putOpenVGCommand(comm, false);
775 int OsdOpenVG::loadFont(bool newfont)
778 float font_size = 16.f;
780 if (!freetype_inited)
782 error = FT_Init_FreeType(&ft_library);
786 Log::getInstance()->log("OSD", Log::WARN, "Could not load freetype %x", error);
791 if (!freetype_inited || newfont)
793 //first get the filename algorith extracted from vdr by Klaus Schmidinger
795 FcPattern* pattern = FcNameParse(reinterpret_cast<FcChar8*>(cur_fontname));
796 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
797 FcConfigSubstitute(NULL, pattern, FcMatchPattern);
798 FcDefaultSubstitute(pattern);
800 FcFontSet* fonts = FcFontSort(NULL, pattern, FcFalse, NULL, &fres);
801 FcChar8* filename = NULL;
805 for (int i = 0; i < fonts->nfont; i++)
808 FcPatternGetBool(fonts->fonts[i], FC_SCALABLE, 0, &canscale);
812 FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &filename);
817 FcFontSetDestroy(fonts);
821 Log::getInstance()->log("OSD", Log::CRIT, "Could not locate a font! Abort!");
825 FcPatternDestroy(pattern);
827 Log::getInstance()->log("OSD", Log::NOTICE, "Load Font %s: %s", cur_fontname, filename);
828 // second load the font
830 error = FT_New_Face(ft_library, reinterpret_cast<const char*>(filename), 0, &new_ft_face);
834 Log::getInstance()->log("OSD", Log::WARN, "Could not load font face %x %s", error, filename);
838 error = FT_Set_Char_Size(new_ft_face, 0, font_size * 256, 0, 0 /*dpi*/);
842 FT_Done_Face(new_ft_face);
843 Log::getInstance()->log("OSD", Log::WARN, "Could not set face size %x", error);
847 FT_Face old_ft_face = ft_face; // do it thread safe
848 ft_face = new_ft_face;
850 if (freetype_inited) FT_Done_Face(old_ft_face);//
852 freetype_inited = true;
855 vgfont = vgCreateFont(0);
858 font_height = ft_face->size->metrics.height / 256.f;
859 cur_char = FT_Get_First_Char(ft_face, &glyph);
860 std::vector<VGubyte> segments;
861 std::vector<VGfloat> coord;
862 segments.reserve(256);
865 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph test %d %x %x %d",cur_char,font_data_end,font_data,glyph);
868 error = FT_Load_Glyph(ft_face, glyph, FT_LOAD_DEFAULT);
872 cur_char = FT_Get_Next_Char(ft_face, cur_char, &glyph);
873 Log::getInstance()->log("OSD", Log::WARN, "Could not load glyph %x %c", error);
878 FT_Outline ot = ft_face->glyph->outline;
882 if (ot.n_contours == 0)
884 path = VG_INVALID_HANDLE;
888 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
889 1.0f, 0.f, 0, 0, VG_PATH_CAPABILITY_ALL);
892 FT_Vector* pt = ot.points;
893 const char* tags = ot.tags;
894 const short* cont = ot.contours;
895 short n_cont = ot.n_contours;
897 //short n_point=ot.n_points;
899 for (short point = 0; n_cont != 0; cont++, n_cont--)
901 short next_cont = *cont + 1;
904 short first_point = point;
906 //Log::getInstance()->log("OSD", Log::DEBUG, "runs %d",*cont);
907 for (; point < next_cont; point++)
909 char tag = tags[point];
910 FT_Vector fpoint = pt[point];
912 // Log::getInstance()->log("OSD", Log::DEBUG, "tag %d point %d %d: %d %d",tag,fpoint.x,fpoint.y,point,n_point);
915 segments.push_back(VG_MOVE_TO);
918 else if (tag & 0x1) //on curve
922 segments.push_back(VG_LINE_TO);
924 else if (last_tag & 0x2)
926 segments.push_back(VG_CUBIC_TO);
930 segments.push_back(VG_QUAD_TO);
938 if (!(last_tag & 0x1))
940 segments.push_back(VG_QUAD_TO);
941 int coord_size = coord.size();
942 VGfloat x = (coord[coord_size - 2] + ((float)fpoint.x) / 256.f) * 0.5f * aspect_correction;
943 VGfloat y = (coord[coord_size - 1] + (font_size - ((float)fpoint.y) / 256.f)) * 0.5f;
951 coord.push_back(((float)fpoint.x)*aspect_correction / 256.);
952 coord.push_back(font_size - ((float)fpoint.y) / 256.);
953 //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]);
956 if (!(last_tag & 0x1))
960 segments.push_back(VG_CUBIC_TO);
964 segments.push_back(VG_QUAD_TO);
967 coord.push_back(((float)pt[first_point].x)*aspect_correction / 256.);
968 coord.push_back(font_size - ((float)pt[first_point].y) / 256.);
971 //segments.push_back(VG_CLOSE_PATH);
974 vgAppendPathData(path, segments.size(), &segments[0], &coord[0]);
975 /* for (int m=0;m<segments.size();m++) {
980 Log::getInstance()->log("OSD", Log::DEBUG, "Move To %g %g",coord[n],coord[n+1]);n+=2; break;
982 Log::getInstance()->log("OSD", Log::DEBUG, "Line To %g %g",coord[n],coord[n+1]);n+=2; break;
984 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;
986 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;
988 Log::getInstance()->log("OSD", Log::DEBUG, "Close Path"); break;
992 //vguRect(path,0.f,0.f,1.f,1.f);
993 //Log::getInstance()->log("OSD", Log::DEBUG, "Create APD Glyph %d %x",segments.size(),vgGetError());
996 VGfloat ori[] = {0.f, 0.f};
997 VGfloat esp[] = {ft_face->glyph->advance.x / 256.f * aspect_correction, ft_face->glyph->advance.y / 256.f};
998 font_exp_x[glyph] = ft_face->glyph->advance.x / 256.f * aspect_correction; //recalculate
1000 vgSetGlyphToPath(vgfont, glyph, path, VG_FALSE, ori, esp);
1002 //Log::getInstance()->log("OSD", Log::DEBUG, "Create Glyph %d %d %x",path,glyph,vgGetError());
1003 if (path != VG_INVALID_HANDLE)
1005 vgDestroyPath(path);
1008 cur_char = FT_Get_Next_Char(ft_face, cur_char, &glyph);
1011 for (int i = 0; i < 256; i++)
1013 unsigned int glyph_index = FT_Get_Char_Index(ft_face, i);
1014 byte_char_width[i] = font_exp_x[glyph_index];
1020 void OsdOpenVG::drawSetTrans(SurfaceInfo& sc)
1022 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1024 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
1025 vgTranslate(0.f + sc.x, -576.f + sc.y);
1027 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1029 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
1030 vgTranslate(0.f + sc.x, -576.f + sc.y);
1032 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
1034 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
1035 vgTranslate(0.f + sc.x, -576.f + sc.y);
1036 clip_shift_x = sc.x;
1037 clip_shift_y = sc.y;
1039 //vgTranslate(0.f+sc.x,576.f-sc.y);
1040 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Translate %g %g",sc.x,sc.y);
1043 void OsdOpenVG::executeDrawCommand(SVGCommand& command)
1045 VGfloat save_matrix[9];
1046 VGfloat save_matrix2[9];
1048 switch (command.instr)
1052 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1054 // rgba = vgGetColor((VGPaint) command.handle);
1055 //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);
1056 //vgSeti(VG_FILL_RULE,);
1058 vgGetMatrix(save_matrix);
1059 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1060 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1061 vgTranslate(command.x, command.y);
1062 vgScale(command.w, command.h);
1063 vgDrawPath(std_paths[command.target.path_index], VG_FILL_PATH);
1064 vgLoadMatrix(save_matrix);
1069 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
1070 vgGetMatrix(save_matrix);
1071 VGfloat imagewidth = vgGetParameteri((VGImage) command.target.image, VG_IMAGE_WIDTH);
1072 VGfloat imageheight = vgGetParameteri((VGImage) command.target.image, VG_IMAGE_HEIGHT);
1074 //vgScale(command.w,command.h);
1076 if (command.handle) //special behaviout for bw images they act as a mask on the current paint
1078 vgTranslate(command.x, command.y);
1079 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1080 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1081 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
1082 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1083 vgScale(aspect_correction, 1.f);
1084 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1085 vgGetMatrix(save_matrix2);
1086 vgScale(imagewidth, imageheight);
1090 //vgScale(720.f/((float)BACKBUFFER_WIDTH), 576.f/((float)BACKBUFFER_HEIGHT));
1091 float scalex = command.w / imagewidth;
1092 float scaley = command.h / imageheight;
1093 float tx = command.x;
1094 float ty = command.y;
1096 if (command.corner == TopLeftLimited)
1098 if (scalex != 0.f && scaley != 0.f)
1100 float imageaspect = imagewidth / imageheight;
1101 float boxaspect = command.w / command.h / aspect_correction;
1103 if (imageaspect > boxaspect)
1106 ty += (command.h - imageheight * scalex / aspect_correction) * 0.5f;
1111 tx += (command.w - imagewidth * scaley * aspect_correction) * 0.5f;
1116 if (scalex == 0.f && scaley == 0.f)
1118 scalex = aspect_correction;
1121 else if (scalex == 0.f)
1123 scalex = scaley * aspect_correction;
1125 else if (scaley == 0.f)
1127 scaley = scalex / aspect_correction;
1130 if (command.corner == BottomRight || command.corner == BottomLeft || command.corner == BottomMiddle)
1132 ty -= imageheight * scaley;
1135 if (command.corner == BottomRight || command.corner == TopRight)
1137 tx -= imagewidth * scalex;
1140 if (command.corner == BottomMiddle || command.corner == TopMiddle)
1142 tx -= imagewidth * scalex * 0.5f;
1145 vgTranslate(tx, ty);
1146 //vgScale(command.w/imagewidth,command.h/imageheight);
1147 vgScale(scalex, scaley);
1148 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1149 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1150 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia Draw Image Scale %g %g %g %g %g %g",command.w,imagewidth,command.h,imageheight,scalex,scaley);
1154 //vgTranslate(200.f,500.f);
1155 //vgScale(100.f,100.f);
1157 vgDrawImage(static_cast<VGImage>(command.target.image));
1159 //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,
1163 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1164 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1165 vgLoadMatrix(save_matrix2);
1168 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
1170 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
1171 vgLoadMatrix(save_matrix);
1176 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1177 vgGetMatrix(save_matrix);
1178 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1179 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1180 vgTranslate(command.x, command.y);
1181 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1182 vgGetMatrix(save_matrix2);
1183 unsigned int glyph_index = FT_Get_Char_Index(ft_face, command.target.textchar);
1184 vgScale(font_exp_x[glyph_index], font_height);
1186 VGfloat gori[] = {0., 0.};
1187 vgSetfv(VG_GLYPH_ORIGIN, 2, gori);
1189 vgDrawGlyph(vgfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1190 //vgDrawPath(std_paths[Rectangle],VG_FILL_PATH);
1191 /* 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,
1193 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1194 vgLoadMatrix(save_matrix);
1195 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1196 vgLoadMatrix(save_matrix2);
1198 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1203 cTeletextChar tchar;
1204 tchar.setInternal(command.target.ttchar);
1205 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1206 vgGetMatrix(save_matrix);
1207 enumTeletextColor ttforegcolour = tchar.GetFGColor();
1208 enumTeletextColor ttbackgcolour = tchar.GetBGColor();
1210 if (tchar.GetBoxedOut())
1212 ttforegcolour = ttcTransparent;
1213 ttbackgcolour = ttcTransparent;
1216 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
1217 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1219 vgTranslate(command.x + command.w * 11.85f * 1.4f, command.y + command.h * 19.75f);
1220 VGfloat gori[] = {0., 0.};
1221 vgSetfv(VG_GLYPH_ORIGIN, 2, gori);
1223 vgScale(-1.4f, 2.f);
1224 unsigned int color = Surface::enumTeletextColorToCoulour(ttbackgcolour).rgba();
1225 color = color << 8 | (color & 0xff000000) >> 24;
1226 vgSetColor(vgttpaint, color);
1227 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_FILL_PATH);
1228 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_STROKE_PATH);
1229 cTeletextChar filled;
1230 filled.setInternal(0x187f);
1231 unsigned int glyph_index = loadTTchar(filled);
1232 vgDrawGlyph(vgttfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1234 color = Surface::enumTeletextColorToCoulour(ttforegcolour).rgba();
1235 color = color << 8 | (color & 0xff000000) >> 24;
1236 vgSetColor(vgttpaint, color);
1237 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_FILL_PATH);
1238 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_STROKE_PATH);
1239 glyph_index = loadTTchar(tchar);
1240 vgDrawGlyph(vgttfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1242 /* Log::getInstance()->log("OSD", Log::DEBUG, "Draw TTchar %x %x %x %x",glyph_index,ttforegcolour,Surface::enumTeletextColorToCoulour(ttforegcolour).rgba(),
1243 vgGetColor(vgttpaint));*/
1245 vgLoadMatrix(save_matrix);
1246 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1247 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1248 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
1253 VGint coords[4] = {0, 0, 0, 0};
1254 coords[0] = ((command.x + clip_shift_x) * ((float)BACKBUFFER_WIDTH) / 720.f);
1255 coords[1] = ((576.f - command.y - clip_shift_y - command.h) * ((float)BACKBUFFER_HEIGHT) / 576.f);
1256 coords[2] = ((command.w - 1.f) * ((float)BACKBUFFER_WIDTH) / 720.f);
1257 coords[3] = ((command.h - 1.f) * ((float)BACKBUFFER_HEIGHT) / 576.f);
1258 vgSetiv(VG_SCISSOR_RECTS, 4, coords);
1260 if (command.w == 0.f && command.h == 0.f)
1261 vgSeti(VG_SCISSORING, VG_FALSE);
1263 vgSeti(VG_SCISSORING, VG_TRUE);
1267 case DrawImageLoading:
1273 //int imcount=0;// this is debug code and should not go into release
1274 unsigned int OsdOpenVG::handleOpenVGCommand(OpenVGCommand& command)
1276 switch (command.task)
1278 case OVGreplacefont:
1280 vgDestroyFont(vgfont);
1284 case OVGdestroyImageRef: //imcount--;
1286 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia Draw Image Destroy %x %d",command.param1,imcount);
1287 vgDestroyImage(static_cast<VGImage>(command.param1));
1290 case OVGdestroyPaint:
1292 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint Destroy %d ",command.param1);
1293 vgDestroyPaint(static_cast<VGPaint>(command.param1));
1296 case OVGcreateImagePalette: //imcount++;
1298 VGImage input = vgCreateImage(VG_A_8, command.param1, command.param2,
1299 VG_IMAGE_QUALITY_NONANTIALIASED |
1300 VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER);
1301 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create palette %d %d %x %d",command.param1,command.param2,vgGetError(),input);
1302 vgImageSubData(input, command.data, command.param1,
1303 VG_A_8, 0, 0, command.param1, command.param2); // upload palettized image data
1304 VGImage handle = vgCreateImage(VG_sRGBA_8888, command.param1, command.param2,
1305 VG_IMAGE_QUALITY_NONANTIALIASED |
1306 VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER);
1307 VGuint* palette = static_cast<VGuint*>(malloc(256 * sizeof(VGuint)));
1308 const VGuint* in_palette = static_cast<const VGuint*>(command.data2);
1310 for (int i = 0; i < 256; i++)
1312 VGuint color = in_palette[i];
1313 palette[i] = color << 8 | (color & 0xff000000) >> 24;
1316 vgLookupSingle(handle, input, palette, VG_ALPHA, VG_FALSE, VG_FALSE);
1318 vgDestroyImage(input);
1322 case OVGcreateMonoBitmap: //imcount++;
1324 VGImage handle = vgCreateImage(VG_A_1, command.param1, command.param2,
1325 VG_IMAGE_QUALITY_FASTER);
1326 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1327 unsigned int buffer_len = (command.param1 * command.param2) >> 3;
1328 unsigned char* buffer = static_cast<unsigned char*>(malloc(buffer_len));
1329 unsigned char* r_buffer1 = buffer;
1330 const unsigned char* r_buffer2 = static_cast<const unsigned char*>(command.data);
1331 unsigned char* buffer_end = buffer + buffer_len;
1333 while (r_buffer1 != buffer_end)
1335 unsigned char byte = *r_buffer2;
1336 *r_buffer1 = ((byte * 0x0802LU & 0x22110LU) | (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
1337 r_buffer1++; r_buffer2++;
1340 vgImageSubData(handle, buffer, command.param1 >> 3, VG_A_1, 0, 0, command.param1, command.param2);
1342 // Log::getInstance()->log("OSD", Log::DEBUG, "Draw create mono2 %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1345 /*case OVGcreateImageFile: {
1348 Image *imagefile=(Image*)command.data;
1350 imagefile->write(&imageblob,"RGBA");
1352 handle=vgCreateImage(VG_sXBGR_8888,imagefile->columns(),imagefile->rows(),
1353 VG_IMAGE_QUALITY_BETTER);
1354 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark1",imagefile->columns(),imagefile->rows(),(unsigned int*)imageblob.data());
1355 vgImageSubData(handle,imageblob.data(),imagefile->columns()*4,
1356 VG_sXBGR_8888,0,0,imagefile->columns(),imagefile->rows());
1357 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create image details %d %d %x mark2",imagefile->columns(),imagefile->rows(),(unsigned int*)imageblob.data());
1359 }catch( Exception &error_ )
1361 Log::getInstance()->log("OSD", Log::DEBUG, "Libmagick hT: %s",error_.what());
1366 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw create file %d %d %x %d",command.param1,command.param2,vgGetError(),handle);
1369 case OVGcreateImageMemory: //imcount++;
1371 const PictureInfo* info = static_cast<const PictureInfo*>(command.data);
1373 //Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateImageMemory %d",imcount);
1374 handle = vgCreateImage(VG_sABGR_8888, info->width, info->height, VG_IMAGE_QUALITY_BETTER);
1375 vgImageSubData(handle, info->image, info->width * 4,
1376 VG_sABGR_8888, 0, 0, info->width, info->height);
1377 info->decoder->freeReference(info->reference);
1379 bool static_image = true;
1381 if (info->lindex & 0xffffffff) static_image = false;
1383 Message* m = new Message();
1384 // We have a pictures! send a message to ourself, to switch to gui thread
1386 m->p_to = Message::CONTROL;
1387 m->data = reinterpret_cast<void*>(handle);
1391 m->message = Message::NEW_PICTURE;
1392 m->tag = info->lindex;
1396 m->message = Message::NEW_PICTURE_STATIC;
1397 m->tag = info->lindex >> 32LL;
1400 MessageQueue::getInstance()->postMessage(m); // inform control about new picture
1405 case OVGcreateEGLImage: //imcount++;
1407 PictureInfo* info = const_cast<PictureInfo*>(static_cast<const PictureInfo*>(command.data));
1410 handle = vgCreateImage(VG_sABGR_8888, info->width, info->height, VG_IMAGE_QUALITY_BETTER);
1411 // Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateEGLImage %d %d %x %d",info->width,info->height, handle,imcount);
1413 info->handle = handle;
1414 info->reference = eglCreateImageKHR(egl_display, egl_context, EGL_VG_PARENT_IMAGE_KHR, reinterpret_cast<EGLClientBuffer>(handle), NULL);
1415 if (info->reference) return true;
1417 Log::getInstance()->log("OSD", Log::DEBUG, "TVMedia OVGcreateEGLImage %d %d %x Fail!", info->width, info->height, handle);
1418 if (handle) vgDestroyImage(handle);
1421 case OVGreadyEGLImage:
1423 PictureInfo* info = const_cast<PictureInfo*>(static_cast<const PictureInfo*>(command.data));
1424 eglDestroyImageKHR(egl_display, info->reference);
1425 bool static_image = true;
1427 if (info->lindex & 0xffffffff) static_image = false;
1429 Message* m = new Message();
1431 m->p_to = Message::CONTROL;
1432 m->data = reinterpret_cast<void*>(info->handle);
1436 m->message = Message::NEW_PICTURE;
1437 m->tag = info->lindex;
1441 m->message = Message::NEW_PICTURE_STATIC;
1442 m->tag = info->lindex >> 32LL;
1445 MessageQueue::getInstance()->postMessage(m); // inform command about new picture
1450 case OVGcreateColorRef:
1453 handle = vgCreatePaint();
1454 const DrawStyle* style = static_cast<const DrawStyle*>(command.data);
1458 case DrawStyle::Color:
1460 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
1461 vgSetColor(handle, command.param1);
1463 //rgba = vgGetColor((VGPaint)handle);
1464 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Paint %d %x %x",handle,command.param1,rgba);
1467 case DrawStyle::GradientLinear:
1469 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
1470 VGfloat params[] = {style->x1, style->y1, style->x2, style->y2, style->r};
1471 //Log::getInstance()->log("OSD", Log::DEBUG, "Draw Gradient %d %g %g %g %g",handle,params[0],params[1],params[2],params[3]);
1472 vgSetParameterfv(handle, VG_PAINT_LINEAR_GRADIENT, 4, params);
1475 case DrawStyle::GradientRadial:
1477 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
1478 VGfloat params[] = {style->x1, style->y1, style->x2, style->y2, style->r};
1479 vgSetParameterfv(handle, VG_PAINT_RADIAL_GRADIENT, 5, params);
1484 if (style->ft == DrawStyle::GradientLinear || style->ft == DrawStyle::GradientRadial)
1486 VGfloat colorramp[5 * 5];
1487 colorramp[0 + 0 * 5] = 0.f;
1488 colorramp[1 + 0 * 5] = style->red / 255.f;
1489 colorramp[2 + 0 * 5] = style->green / 255.f;
1490 colorramp[3 + 0 * 5] = style->blue / 255.f;
1491 colorramp[4 + 0 * 5] = style->alpha / 255.f;
1493 for (int i = 0; i < (style->num_colors - 1); i++)
1495 colorramp[0 + (i + 1) * 5] = style->grad_pos[i];
1496 colorramp[1 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].red) / 255.f;
1497 colorramp[2 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].green) / 255.f;
1498 colorramp[3 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].blue) / 255.f;
1499 colorramp[4 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].alpha) / 255.f;
1502 colorramp[0 + (style->num_colors) * 5] = 1.f;
1503 colorramp[1 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].red) / 255.f;
1504 colorramp[2 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].green) / 255.f;
1505 colorramp[3 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].blue) / 255.f;
1506 colorramp[4 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].alpha) / 255.f;
1507 vgSetParameteri(handle, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_REFLECT);
1508 vgSetParameteri(handle, VG_PAINT_COLOR_RAMP_PREMULTIPLIED, VG_FALSE);
1509 vgSetParameterfv(handle, VG_PAINT_COLOR_RAMP_STOPS, 5 + (style->num_colors) * 5, colorramp);
1515 case OVGimageUploadLine:
1522 void OsdOpenVG::destroyImageRef(ImageIndex index)
1524 struct OpenVGCommand comm;
1525 comm.task = OVGdestroyImageRef;
1526 comm.param1 = index;
1527 putOpenVGCommand(comm, false);
1530 bool OsdOpenVG::getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length)
1532 if (sa_MAX > static_id)
1534 *userdata = static_artwork_begin[static_id];
1535 *length = static_artwork_end[static_id] - static_artwork_begin[static_id];
1544 void OsdOpenVG::createPicture(struct PictureInfo& pict_inf)
1546 struct OpenVGCommand comm;
1547 Log::getInstance()->log("OsdOpenVG", Log::DEBUG, "TVMedia Create Picture %d", pict_inf.type);
1549 if (pict_inf.type == PictureInfo::RGBAMemBlock)
1551 comm.task = OVGcreateImageMemory;
1552 comm.data = new PictureInfo(pict_inf);
1553 putOpenVGCommand(comm, false);
1555 else if (pict_inf.type == PictureInfo::EGLImage)
1557 comm.task = OVGreadyEGLImage;
1558 comm.data = new PictureInfo(pict_inf);
1559 putOpenVGCommand(comm, false);
1564 pict_inf.decoder->freeReference(pict_inf.reference);
1568 bool OsdOpenVG::getEGLPicture(struct OsdVector::PictureInfo& info, EGLDisplay* display)
1570 struct OpenVGCommand comm;
1571 info.type = PictureInfo::EGLImage;
1572 comm.task = OVGcreateEGLImage;
1574 *display = egl_display;
1575 return putOpenVGCommand(comm, true);
1578 ImageIndex OsdOpenVG::createMonoBitmap(void* base, int width, int height)
1580 struct OpenVGCommand comm;
1581 comm.task = OVGcreateMonoBitmap;
1582 comm.param1 = width;
1583 comm.param2 = height;
1585 return putOpenVGCommand(comm, true);
1588 ImageIndex OsdOpenVG::createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data)
1590 struct OpenVGCommand comm;
1591 comm.task = OVGcreateImagePalette;
1592 comm.param1 = width;
1593 comm.param2 = height;
1594 comm.data = image_data;
1595 comm.data2 = palette_data;
1596 return putOpenVGCommand(comm, true);
1599 void OsdOpenVG::destroyDrawStyleHandle(VectorHandle index)
1601 struct OpenVGCommand comm;
1602 comm.task = OVGdestroyPaint;
1603 comm.param1 = index;
1604 putOpenVGCommand(comm, false);
1607 VectorHandle OsdOpenVG::createDrawStyleHandle(const DrawStyle& c)
1609 unsigned int col = c.rgba();
1610 struct OpenVGCommand comm;
1611 comm.task = OVGcreateColorRef;
1612 comm.param1 = col << 8 | (col & 0xff000000) >> 24;
1614 return putOpenVGCommand(comm, true);