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 static const char* TAG = "OsdOpenVG";
36 #define EXTERNALPICTURE(name, fname, fileextension) extern uint8_t name ## _data[] asm("_binary_other_"#fname"_"#fileextension"_start"); \
37 extern uint8_t name ## _data_end[] asm("_binary_other_"#fname"_"#fileextension"_end");
41 #undef EXTERNALPICTURE
43 #define BACKBUFFER_WIDTH 1280
44 #define BACKBUFFER_HEIGHT 720
46 OsdOpenVG::OsdOpenVG()
50 lastrendertime = getTimeMS();
52 const char* fontname = "Droid Sans:style=Regular";
53 cur_fontname = static_cast<char*>(malloc(strlen(fontname) + 1));
54 strcpy(cur_fontname, fontname);
56 #define EXTERNALPICTURE(name, fname, fileextension) static_artwork_begin[sa_ ## name]=name ## _data;
60 #undef EXTERNALPICTURE
61 #define EXTERNALPICTURE(name, fname, fileextension) static_artwork_end[sa_ ## name]=name ## _data_end;
65 #undef EXTERNALPICTURE
68 OsdOpenVG::~OsdOpenVG()
70 if (initted) shutdown();
72 if (cur_fontname) free(cur_fontname);
74 if (freetype_inited) FT_Done_Face(ft_face);
76 for (char* c : fontnames) free(c);
77 for (char* c : fontnames_keys) free(c);
85 if (initted) return 0;
89 //First get connection to egl
90 egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
91 if (egl_display == EGL_NO_DISPLAY)
93 LogNT::getInstance()->crit(TAG, "Could not get egl display! {:#x}", eglGetError());
98 if (eglInitialize(egl_display, NULL, NULL) == EGL_FALSE)
100 LogNT::getInstance()->crit(TAG, "Initialising display failed! {:#x}", eglGetError());
105 const char* query_str = eglQueryString(egl_display, EGL_CLIENT_APIS);
107 if (query_str) LogNT::getInstance()->debug(TAG, query_str);
108 else LogNT::getInstance()->warn(TAG, "Could not query display {:#x}", eglGetError());
110 query_str = eglQueryString(egl_display, EGL_EXTENSIONS);
112 if (query_str) LogNT::getInstance()->info(TAG, query_str);
113 else LogNT::getInstance()->warn(TAG, "Could not query display {:#x}", eglGetError());
115 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
117 LogNT::getInstance()->warn(TAG, "Binding openvg api failed! {:#x}", eglGetError());
122 const EGLint attributs[] =
124 EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
125 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
126 EGL_CONFORMANT, EGL_OPENVG_BIT,
128 }; // Here, we might have to select the resolution!
132 if (eglChooseConfig(egl_display, attributs, &egl_ourconfig, 1, &number) == EGL_FALSE)
134 LogNT::getInstance()->warn(TAG, "Choosing egl config failed! {:#x}", eglGetError());
139 egl_context = eglCreateContext(egl_display, egl_ourconfig, NULL, NULL);
141 if (egl_context == EGL_NO_CONTEXT)
143 LogNT::getInstance()->warn(TAG, "Creating egl context failed! {:#x}", eglGetError());
148 // warning broadcom specific, get display size!
149 display_width = display_height = 0;
151 if (graphics_get_display_size(0, reinterpret_cast<uint32_t*>(&display_width), reinterpret_cast<uint32_t*>(&display_height)) < 0)
153 LogNT::getInstance()->warn(TAG, "Getting display size failed! (BCM API)");
158 LogNT::getInstance()->info(TAG, "Displaysize is {} x {}", display_width, display_height);
159 VC_RECT_T dst_rect = {0, 0, display_width, display_height};
160 VC_RECT_T src_rect = {0, 0, BACKBUFFER_WIDTH << 16, BACKBUFFER_HEIGHT << 16};
161 VC_RECT_T src_rect_bg = {0, 0, 16 << 16, 16 << 16};
162 // VC_RECT_T src_rect_im={0,0,16,16};
164 uint32_t back_image_ptr;
165 bcm_backres = vc_dispmanx_resource_create(VC_IMAGE_RGBX32, 16, 16, &back_image_ptr);
167 updateBackgroundColor(DrawStyle::WALLPAPER);
169 DISPMANX_UPDATE_HANDLE_T bcm_update;
170 bcm_display = vc_dispmanx_display_open(0);
171 bcm_update = vc_dispmanx_update_start(0);
172 bcm_element = vc_dispmanx_element_add(bcm_update, bcm_display,
174 &src_rect, DISPMANX_PROTECTION_NONE, 0, 0, static_cast<DISPMANX_TRANSFORM_T>(0));
177 bcm_background = vc_dispmanx_element_add(bcm_update, bcm_display,
178 0, &dst_rect, bcm_backres,
179 &src_rect_bg, DISPMANX_PROTECTION_NONE, 0, 0, static_cast<DISPMANX_TRANSFORM_T>(0));
181 vc_dispmanx_update_submit_sync(bcm_update);
183 static EGL_DISPMANX_WINDOW_T nativewindow;
184 nativewindow.element = bcm_element;
185 nativewindow.height = BACKBUFFER_HEIGHT;
186 nativewindow.width = BACKBUFFER_WIDTH;
188 egl_surface = eglCreateWindowSurface(egl_display, egl_ourconfig, &nativewindow, NULL);
189 if (egl_surface == EGL_NO_SURFACE)
191 LogNT::getInstance()->warn(TAG, "Creating egl window surface failed!");
196 LogNT::getInstance()->debug(TAG, "Making egl current in SYS_gettid: {}", syscall(SYS_gettid));
198 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
200 LogNT::getInstance()->warn(TAG, "Making egl Current failed");
207 query_str = reinterpret_cast<const char*>(vgGetString(VG_VERSION));
209 if (query_str) LogNT::getInstance()->info(TAG, query_str);
210 else LogNT::getInstance()->warn(TAG, "Could not query display {:#x}", vgGetError());
212 query_str = reinterpret_cast<const char*>(vgGetString(VG_VENDOR));
214 if (query_str) LogNT::getInstance()->info(TAG, query_str);
215 else LogNT::getInstance()->warn(TAG, "Could not query display {:#x}", vgGetError());
217 query_str = reinterpret_cast<const char*>(vgGetString(VG_RENDERER));
219 if (query_str) LogNT::getInstance()->info(TAG, query_str);
220 else LogNT::getInstance()->warn(TAG, "Could not query display {:#x}", vgGetError());
222 query_str = reinterpret_cast<const char*>(vgGetString(VG_EXTENSIONS));
224 if (query_str) LogNT::getInstance()->info(TAG, query_str);
225 else LogNT::getInstance()->warn(TAG, "Could not query display {:#x}", vgGetError());
227 aspect_correction = ((float)BACKBUFFER_HEIGHT) / 576.f / (((float)BACKBUFFER_WIDTH) / 720.f);
230 if (!fontnames.size())
232 //inspired by and copied from vdr's code
234 FcObjectSet* objset = FcObjectSetBuild(FC_FAMILY, FC_STYLE, NULL);
235 FcPattern* pattern = FcPatternCreate();
236 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
237 FcFontSet* fonts = FcFontList(NULL, pattern, objset);
239 for (int i = 0; i < fonts->nfont; i++)
241 char* s = reinterpret_cast<char*>(FcNameUnparse(fonts->fonts[i]));
245 char* c = strchr(s, ':');
249 char* s2 = strchr(c + 1, ',');
254 char* p = strchr(s, ',');
259 else memmove(p, c, strlen(c) + 1);
262 char* key = (char*)malloc(strlen(s) + 1);
264 fontnames_keys.push_back(key);
265 char* s2 = strstr(s, "style=");
269 memmove(s2, s2 + 6, strlen(s2 + 6) + 1);
272 fontnames.push_back(s);
276 FcFontSetDestroy(fonts);
277 FcPatternDestroy(pattern);
278 FcObjectSetDestroy(objset);
281 if (!loadFont(false))
286 vgttfont = vgCreateFont(0);
287 vgttpaint = vgCreatePaint();
288 vgSetParameteri( vgttpaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
289 vgSetColor(vgttpaint, 0xffffffff);
291 eglSwapInterval(egl_display, 1);
293 LogNT::getInstance()->debug(TAG, "Making egl current out SYS_gettid {}", syscall(SYS_gettid));
294 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
295 //Now we will create the Screen
296 initted = true; // must set this here or create surface won't work
298 /*if (((VideoOMX*)Video::getInstance())->initUsingOSDObjects()!=1) { //call Video for init stuff
303 renderThreadMutex.lock(); // start-protect
305 renderThread = std::thread( [this]
307 renderThreadMutex.lock();
308 renderThreadMutex.unlock();
311 renderThreadMutex.unlock();
317 #ifdef PICTURE_DECODER_OMX
318 // imageomx = new ImageOMX(&reader);
319 // reader.addDecoder(imageomx);
321 imageomx2 = new ImageOMX2(/*egl_display*/);
322 reader.addDecoder(imageomx2);
328 void OsdOpenVG::renderThreadStop()
330 LogNT::getInstance()->warn(TAG, "renderThreadStop");
332 renderThreadMutex.lock();
333 renderThreadReq = 2; // req-stop
334 renderThreadCond.notify_one(); // in case renderLoop is in cond_wait
335 renderThreadMutex.unlock();
339 int OsdOpenVG::stopUpdate()
342 processOpenVGCommands();
346 int OsdOpenVG::shutdown()
350 #ifdef PICTURE_DECODER_OMX
351 // if (imageomx) reader.removeDecoder(imageomx);
353 if (imageomx2) reader.removeDecoder(imageomx2);
357 if (!initted) return 0;
360 LogNT::getInstance()->debug(TAG, "shutdown mark1");
362 LogNT::getInstance()->debug(TAG, "shutdown mark1a");
364 //(((VideoOMX*)Video::getInstance())->shutdownUsingOSDObjects());
365 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
367 LogNT::getInstance()->warn(TAG, "Making egl Current failed in shutdown {:#x}", eglGetError());
370 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
372 LogNT::getInstance()->warn(TAG, "Binding openvg api thread failed! {:#x}", eglGetError());
375 LogNT::getInstance()->debug(TAG, "shutdown mark2");
376 processOpenVGCommands();
377 LogNT::getInstance()->debug(TAG, "shutdown mark3");
382 //purgeAllReferences();
384 vgDestroyFont(vgfont);
385 vgDestroyFont(vgttfont);
386 vgDestroyPaint(vgttpaint);
388 float colclear[] = {0.8f, 0.8f, 0.8f, 1.f};
389 vgSetfv(VG_CLEAR_COLOR, 4, colclear);
390 vgClear(0, 0, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT);
391 eglSwapBuffers(egl_display, egl_surface);
392 LogNT::getInstance()->debug(TAG, "Making egl current out final");
393 eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
395 if (eglDestroySurface(egl_display, egl_surface) == EGL_FALSE)
397 LogNT::getInstance()->error(TAG, "eglDestroySurface failed {:#x}", eglGetError());
400 if (eglDestroyContext(egl_display, egl_context) == EGL_FALSE)
402 LogNT::getInstance()->error(TAG, "eglDestroyContext failed {:#x}", eglGetError());
405 if (eglTerminate(egl_display) == EGL_FALSE)
407 LogNT::getInstance()->error(TAG, "eglTerminate failed {:#x}", eglGetError());
410 DISPMANX_UPDATE_HANDLE_T bcm_update;
411 bcm_update = vc_dispmanx_update_start(0);
413 vc_dispmanx_element_remove(bcm_update, bcm_element);
414 vc_dispmanx_element_remove(bcm_update, bcm_background);
415 vc_dispmanx_update_submit_sync(bcm_update);
416 vc_dispmanx_resource_delete(bcm_backres);
418 vc_dispmanx_display_close(bcm_display);
422 // OSDOVG-ROD-EXPERIMENT - temp hack to allow OsdVector to signal the thread in OsdOpenVG
423 void OsdOpenVG::doRender()
425 LogNT::getInstance()->debug(TAG, "Nudge render thread");
427 // signal renderLoop to go-around (from putOpenVGCommand)
428 renderThreadMutex.lock();
429 if (renderThreadReq == 0) renderThreadReq = 1;
430 renderThreadCond.notify_one();
431 renderThreadMutex.unlock();
435 * OSDOVG-ROD-EXPERIMENT
437 * To switch OsdOpenVG to render-on-demand instead of rendering in a loop
440 * More responsive OSD
441 * Cuts 5% constant CPU usage
442 * Seems to have tickled the GFX corruption bug, might make it easier to find that
445 * There's a comment about video tearing if render is called too often.
446 * Will tearing show up in on-demand mode?
447 * Moves away from conventional FPS type render loop. VOMP doesn't use 3D GFX / animations
448 * currently, so this doesn't matter at the moment?
449 * Code needs updating to call doRender,
450 * e.g. backing out of the options screen doesn't redraw VWelcome, fixed now
452 * Maybe have a hybrid system. One that normally works on-demand but can
453 * also switch to looping on the fly if necessary.
457 void OsdOpenVG::renderLoop()
459 // We have to claim the egl context for this thread
460 LogNT::getInstance()->info(TAG, "Entering drawing thread");
462 if (eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context) == EGL_FALSE)
464 LogNT::getInstance()->warn(TAG, "Making egl Current failed in thread {:#x}", eglGetError());
468 if (eglBindAPI(EGL_OPENVG_API) == EGL_FALSE)
470 LogNT::getInstance()->warn(TAG, "Binding openvg api thread failed! {:#x}", eglGetError());
474 std::unique_lock<std::mutex> ul(renderThreadMutex, std::defer_lock);
481 long long time1 = getTimeMS();
483 // OSDOVG-ROD-EXPERIMENT - always render, but only when signalled to
484 if (1) // ((time1 - lastrendertime) > 200) //5 fps for OSD updates are enough, avoids tearing
489 LogNT::getInstance()->trace(TAG, "EXPERIMENT - render");
492 lastrendertime = getTimeMS();
498 ts = time1 - lastrendertime;
501 if (processOpenVGCommands()) ts = 0;
504 if (renderThreadReq == 2)
506 if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) == EGL_FALSE)
507 LogNT::getInstance()->warn(TAG, "Making egl Current out thread failed");
514 // OSDOVG-ROD-EXPERIMENT
517 renderThreadCond.wait(ul, [this]{ return renderThreadReq != 0; }); // experiment! always wait, no time limit
518 //renderThreadCond.wait_for(ul, std::chrono::milliseconds(ts), [this]{ return renderThreadReq != 0; });
520 if (renderThreadReq == 2)
522 if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) == EGL_FALSE)
523 LogNT::getInstance()->warn(TAG, "Making egl Current out thread failed");
528 if (renderThreadReq == 0) abort(); // OSDOVG-ROD-EXPERIMENT - check this never happens - confirmed
530 // Either timeout or renderThreadReq == 1 - go around
539 UINT OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm, bool wait)
541 if (wait) comm.response = new OpenVGResponse;
543 std::unique_lock<std::mutex> ul(taskmutex); // locks
544 vgcommands.push_back(comm);
547 // signal renderLoop to go-around
548 renderThreadMutex.lock();
549 if (renderThreadReq == 0) renderThreadReq = 1;
550 renderThreadCond.notify_one();
551 renderThreadMutex.unlock();
556 // Wait until done is true and we are signalled. If done is already true, this returns immediately
557 comm.response->doneCond.wait(ul, [&comm]{ return comm.response->done; });
559 // Now response->done = true, mutex is locked, we have been signalled
562 UINT toReturn = comm.response->result;
563 delete comm.response;
567 bool OsdOpenVG::processOpenVGCommands()
572 while (vgcommands.size() > 0)
576 OpenVGCommand comm = vgcommands.front();
577 vgcommands.pop_front();
581 UINT vgResult = handleOpenVGCommand(comm);
585 if (comm.response) // There is a response object, a thread is waiting
587 comm.response->result = vgResult;
588 comm.response->done = true;
589 comm.response->doneCond.notify_one();
597 void OsdOpenVG::InternalRendering()
600 Colour bg = DrawStyle::WALLPAPER;
601 float colclear[] = {1.f, 1.0f, 1.f, 1.f};
603 if (bg.alpha == 0) colclear[3] = 0.f;
605 vgSetfv(VG_CLEAR_COLOR, 4, colclear);
606 vgClear(0, 0, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT);
607 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
609 drawSurfaces(); //iterate through and draws all commands
611 //Show it to the user!
612 eglSwapBuffers(egl_display, egl_surface);
616 // --------------------------------------------------------------------------------------------------------------------------
619 void OsdOpenVG::purgeAllReferences()
622 drawstyleHandlesRefCounts.clear(); // remove all references
625 map<void *,VectorHandleImage>::iterator mitty=monobitmaps.begin();
626 while (mitty!=monobitmaps.end()) {
627 vgDestroyImage((VGImage)(*mitty).second);
632 / *map<string,VectorHandleImage>::iterator jitty=jpegs.begin();
633 while (jitty!=jpegs.end()) {
634 vgDestroyImage((VGImage)(*jitty).second);
639 map<TVMediaInfo,VectorHandleImage>::iterator titty=tvmedias.begin();
640 while (titty!=tvmedias.end()) {
641 vgDestroyImage((VGImage)(*titty).second);
646 map<pair<Colour*,unsigned int>,unsigned int>::iterator sitty=drawstyleHandles.begin();
647 while (sitty!=drawstyleHandles.end()) {
648 vgDestroyPaint((VGPaint)(*sitty).second);
651 drawstyleHandles.clear();
655 void OsdOpenVG::updateBackgroundColor(DrawStyle bg)
657 unsigned int color[16 * 16];
659 if (!bcm_backres) return;
661 VC_RECT_T src_rect_im = {0, 0, 16, 16};
663 if (bg.ft != DrawStyle::GradientLinear)
668 //memset(color,0xFF,sizeof(unsigned int)*4*8);
669 for (int j = 0; j < 16; j++)
671 int helpr = (((15 - j) * bg.red) + (j * bg.grad_col[0].red)) / 15;
672 int helpb = (((15 - j) * bg.blue) + (j * bg.grad_col[0].blue)) / 15;
673 int helpg = (((15 - j) * bg.green) + (j * bg.grad_col[0].green)) / 15;
674 //unsigned int cur_col=help | (help<< 8) | (help<< 16) | (0xFF<< 24);
675 unsigned int cur_col = helpr | (helpg << (8)) | (helpb << (16)) | (0xFF << (24));
677 for (int i = 0; i < 16; i++)
679 color[i + 16 * j] = cur_col;
683 vc_dispmanx_resource_write_data(bcm_backres, VC_IMAGE_RGBX32, 16 * 4, color, &src_rect_im);
686 void OsdOpenVG::getScreenSize(int& width, int& height)
688 width = BACKBUFFER_WIDTH;
689 height = BACKBUFFER_HEIGHT;
692 void OsdOpenVG::getRealScreenSize(int& width, int& height)
694 width = display_width;
695 height = display_height;
698 bool OsdOpenVG::screenShotInternal(void* buffer, int width, int height, bool includeOSD)
700 if (!initted) return false;
702 if (!buffer) return false;
704 DISPMANX_RESOURCE_HANDLE_T res;
705 DISPMANX_DISPLAY_HANDLE_T display;
709 res = vc_dispmanx_resource_create(VC_IMAGE_RGBA32, width, height, &image_ptr);
710 display = vc_dispmanx_display_open(0);
714 vc_dispmanx_snapshot(display, res,
715 static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_NO_RGB | DISPMANX_SNAPSHOT_FILL/*|DISPMANX_SNAPSHOT_PACK*/));
719 vc_dispmanx_snapshot(display, res,
720 static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_FILL));
723 vc_dispmanx_rect_set(&rect, 0, 0, width, height);
724 vc_dispmanx_resource_read_data(res, &rect, buffer, width * 4);
725 vc_dispmanx_resource_delete(res);
726 vc_dispmanx_display_close(display);
730 void OsdOpenVG::initPaths()
733 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
734 VG_PATH_DATATYPE_F, 1.f, 0.f,
735 0, 0, VG_PATH_CAPABILITY_ALL);
737 vguLine(current, 0.f, 0.f, 1.f, 0.f);
739 std_paths[PIHorzLine] = current;
741 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
742 VG_PATH_DATATYPE_F, 1.f, 0.f,
743 0, 0, VG_PATH_CAPABILITY_ALL);
744 vguLine(current, 0.f, 0.f, 0.f, 1.f);
746 std_paths[PIVertLine] = current;
748 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
749 VG_PATH_DATATYPE_F, 1.f, 0.f,
750 0, 0, VG_PATH_CAPABILITY_ALL);
751 //vguRect(current,0.f,0.f,1.f,1.f);
752 vguRect(current, 0.f, 0.f, 1.f, 1.f);
754 std_paths[PIRectangle] = current;
756 current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
757 VG_PATH_DATATYPE_F, 1.f, 0.f,
759 vguEllipse(current, 0.f, 0.f, 1.f, 1.f);
761 std_paths[PIPoint] = current;
764 void OsdOpenVG::destroyPaths()
766 vgDestroyPath(std_paths[PIHorzLine]);
767 vgDestroyPath(std_paths[PIVertLine]);
768 vgDestroyPath(std_paths[PIRectangle]);
769 vgDestroyPath(std_paths[PIPoint]);
774 float OsdOpenVG::getFontHeight()
776 return font_height; //dummy
779 float OsdOpenVG::getCharWidth(wchar_t c)
781 if (c < 256) return byte_char_width[c];
783 unsigned int glyph_index = FT_Get_Char_Index(ft_face, c);
784 return font_exp_x[glyph_index];
787 unsigned int OsdOpenVG::loadTTchar(cTeletextChar c)
789 unsigned int glyph_index = c.getGlyphIndex();
791 if (tt_font_chars.find(glyph_index) != tt_font_chars.end())
796 unsigned int buffer[10];
797 const VGfloat glyphOrigin[] = { 0.f, 0.f };
798 const VGfloat escapement[] = { 12.f, 0.f };
799 unsigned int* charmap = GetFontChar(c, buffer);
801 if (!charmap) return 0; //invalid char
803 for (int i = 0; i < 10; i++)
805 buffer[i] = charmap[i] >> 4;
808 VGImage handle = vgCreateImage(
812 VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER
813 | VG_IMAGE_QUALITY_BETTER);
814 vgImageSubData(handle, buffer, 4, VG_A_1, 0, 0, 12, 10);
818 handle, const_cast<VGfloat*>(glyphOrigin), const_cast<VGfloat*>(escapement));
819 vgDestroyImage(handle);
820 tt_font_chars[glyph_index] = 1;
825 int OsdOpenVG::getFontNames(const char*** names, const char*** names_keys)
827 *names = const_cast<const char**>(&(fontnames[0]));
828 *names_keys = const_cast<const char**>(&(fontnames_keys[0]));
829 return fontnames.size();
832 void OsdOpenVG::setFont(const char* fontname)
834 if (strcmp(fontname, cur_fontname))
837 if (cur_fontname) free(cur_fontname);
839 cur_fontname = static_cast<char*>(malloc(strlen(fontname) + 1));
840 strcpy(cur_fontname, fontname);
842 struct OpenVGCommand comm;
843 comm.task = OVGreplacefont;
844 putOpenVGCommand(comm, false);
848 int OsdOpenVG::loadFont(bool newfont)
851 float font_size = 16.f;
853 if (!freetype_inited)
855 error = FT_Init_FreeType(&ft_library);
859 LogNT::getInstance()->warn(TAG, "Could not load freetype {:#x}", error);
864 if (!freetype_inited || newfont)
866 //first get the filename algorith extracted from vdr by Klaus Schmidinger
868 FcPattern* pattern = FcNameParse(reinterpret_cast<FcChar8*>(cur_fontname));
869 FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
870 FcConfigSubstitute(NULL, pattern, FcMatchPattern);
871 FcDefaultSubstitute(pattern);
873 FcFontSet* fonts = FcFontSort(NULL, pattern, FcFalse, NULL, &fres);
874 FcChar8* filename = NULL;
878 for (int i = 0; i < fonts->nfont; i++)
881 FcPatternGetBool(fonts->fonts[i], FC_SCALABLE, 0, &canscale);
885 FcPatternGetString(fonts->fonts[i], FC_FILE, 0, &filename);
890 FcFontSetDestroy(fonts);
894 LogNT::getInstance()->crit(TAG, "Could not locate a font! Abort!");
898 FcPatternDestroy(pattern);
900 LogNT::getInstance()->info(TAG, "Load Font {}: {}", cur_fontname, filename);
901 // second load the font
903 error = FT_New_Face(ft_library, reinterpret_cast<const char*>(filename), 0, &new_ft_face);
907 LogNT::getInstance()->warn(TAG, "Could not load font face {:#x} {}", error, filename);
911 error = FT_Set_Char_Size(new_ft_face, 0, font_size * 256, 0, 0 /*dpi*/);
915 FT_Done_Face(new_ft_face);
916 LogNT::getInstance()->warn(TAG, "Could not set face size {:#x}", error);
920 FT_Face old_ft_face = ft_face; // do it thread safe
921 ft_face = new_ft_face;
923 if (freetype_inited) FT_Done_Face(old_ft_face);//
925 freetype_inited = true;
928 vgfont = vgCreateFont(0);
931 font_height = ft_face->size->metrics.height / 256.f;
932 cur_char = FT_Get_First_Char(ft_face, &glyph);
933 std::vector<VGubyte> segments;
934 std::vector<VGfloat> coord;
935 segments.reserve(256);
938 //LogNT::getInstance()->debug(TAG, "Create Glyph test {} {} {} {}",cur_char,font_data_end,font_data,glyph);
941 error = FT_Load_Glyph(ft_face, glyph, FT_LOAD_DEFAULT);
945 cur_char = FT_Get_Next_Char(ft_face, cur_char, &glyph);
946 LogNT::getInstance()->warn(TAG, "Could not load glyph {:#x} {}", error);
951 FT_Outline ot = ft_face->glyph->outline;
955 if (ot.n_contours == 0)
957 path = VG_INVALID_HANDLE;
961 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
962 1.0f, 0.f, 0, 0, VG_PATH_CAPABILITY_ALL);
965 FT_Vector* pt = ot.points;
966 const char* tags = ot.tags;
967 const short* cont = ot.contours;
968 short n_cont = ot.n_contours;
970 //short n_point=ot.n_points;
972 for (short point = 0; n_cont != 0; cont++, n_cont--)
974 short next_cont = *cont + 1;
977 short first_point = point;
979 //LogNT::getInstance()->debug(TAG, "runs {}", *cont);
980 for (; point < next_cont; point++)
982 char tag = tags[point];
983 FT_Vector fpoint = pt[point];
985 // LogNT::getInstance()->debug(TAG, "tag %d point {} {}: {} {}",tag,fpoint.x,fpoint.y,point,n_point);
988 segments.push_back(VG_MOVE_TO);
991 else if (tag & 0x1) //on curve
995 segments.push_back(VG_LINE_TO);
997 else if (last_tag & 0x2)
999 segments.push_back(VG_CUBIC_TO);
1003 segments.push_back(VG_QUAD_TO);
1011 if (!(last_tag & 0x1))
1013 segments.push_back(VG_QUAD_TO);
1014 int coord_size = coord.size();
1015 VGfloat x = (coord[coord_size - 2] + ((float)fpoint.x) / 256.f) * 0.5f * aspect_correction;
1016 VGfloat y = (coord[coord_size - 1] + (font_size - ((float)fpoint.y) / 256.f)) * 0.5f;
1024 coord.push_back(((float)fpoint.x)*aspect_correction / 256.);
1025 coord.push_back(font_size - ((float)fpoint.y) / 256.);
1026 //LogNT::getInstance()->debug(TAG, "Create APD Glyph coord {} {} {} {}",fpoint.x,fpoint.y,coord[coord.size()-2],coord[coord.size()-1]);
1029 if (!(last_tag & 0x1))
1033 segments.push_back(VG_CUBIC_TO);
1037 segments.push_back(VG_QUAD_TO);
1040 coord.push_back(((float)pt[first_point].x)*aspect_correction / 256.);
1041 coord.push_back(font_size - ((float)pt[first_point].y) / 256.);
1044 //segments.push_back(VG_CLOSE_PATH);
1047 vgAppendPathData(path, segments.size(), &segments[0], &coord[0]);
1048 /* for (int m=0;m<segments.size();m++) {
1050 switch (segments[m])
1053 LogNT::getInstance()->debug(TAG, "Move To {} {}",coord[n],coord[n+1]);n+=2; break;
1055 LogNT::getInstance()->debug(TAG, "Line To {} {}",coord[n],coord[n+1]);n+=2; break;
1057 LogNT::getInstance()->debug(TAG, "Cubic To {} {} {} {} {} {}",coord[n],coord[n+1],coord[n+2],coord[n+3],coord[n+4],coord[n+5]);n+=6; break;
1059 LogNT::getInstance()->debug(TAG, "Quad To {} {} {} {}",coord[n],coord[n+1],coord[n+2],coord[n+3]);n+=4; break;
1061 LogNT::getInstance()->debug(TAG, "Close Path"); break;
1065 //vguRect(path,0.f,0.f,1.f,1.f);
1066 //LogNT::getInstance()->debug(TAG, "Create APD Glyph {} {:#x}",segments.size(),vgGetError());
1069 VGfloat ori[] = {0.f, 0.f};
1070 VGfloat esp[] = {ft_face->glyph->advance.x / 256.f * aspect_correction, ft_face->glyph->advance.y / 256.f};
1071 font_exp_x[glyph] = ft_face->glyph->advance.x / 256.f * aspect_correction; //recalculate
1073 vgSetGlyphToPath(vgfont, glyph, path, VG_FALSE, ori, esp);
1075 //LogNT::getInstance()->debug(TAG, "Create Glyph {} {} {:#x}",path,glyph,vgGetError());
1076 if (path != VG_INVALID_HANDLE)
1078 vgDestroyPath(path);
1081 cur_char = FT_Get_Next_Char(ft_face, cur_char, &glyph);
1084 for (int i = 0; i < 256; i++)
1086 unsigned int glyph_index = FT_Get_Char_Index(ft_face, i);
1087 byte_char_width[i] = font_exp_x[glyph_index];
1093 void OsdOpenVG::drawSetTrans(SurfaceInfo& sc)
1095 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1097 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
1098 vgTranslate(0.f + sc.x, -576.f + sc.y);
1100 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1102 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
1103 vgTranslate(0.f + sc.x, -576.f + sc.y);
1105 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
1107 vgScale(((float)BACKBUFFER_WIDTH) / 720.f, -((float)BACKBUFFER_HEIGHT) / 576.f);
1108 vgTranslate(0.f + sc.x, -576.f + sc.y);
1109 clip_shift_x = sc.x;
1110 clip_shift_y = sc.y;
1112 //vgTranslate(0.f+sc.x,576.f-sc.y);
1113 //LogNT::getInstance()->debug(TAG, "Draw Translate {} {}",sc.x,sc.y);
1116 void OsdOpenVG::executeDrawCommand(SVGCommand& command)
1118 VGfloat save_matrix[9];
1119 VGfloat save_matrix2[9];
1121 switch (command.instr)
1125 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1127 // rgba = vgGetColor((VGPaint) command.handle);
1128 //LogNT::getInstance()->debug(TAG, "Draw Path {} {:#x} {} {} {} {}",command.handle,command.target.path_index,command.x,command.y,command.w,command.h);
1129 //vgSeti(VG_FILL_RULE,);
1131 vgGetMatrix(save_matrix);
1132 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1133 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1134 vgTranslate(command.x, command.y);
1135 vgScale(command.w, command.h);
1136 vgDrawPath(std_paths[command.target.path_index], VG_FILL_PATH);
1137 vgLoadMatrix(save_matrix);
1142 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
1143 vgGetMatrix(save_matrix);
1144 VGfloat imagewidth = vgGetParameteri(static_cast<VGImage>(command.target.image), VG_IMAGE_WIDTH);
1145 VGfloat imageheight = vgGetParameteri(static_cast<VGImage>(command.target.image), VG_IMAGE_HEIGHT);
1147 //vgScale(command.w,command.h);
1149 if (command.handle) //special behaviout for bw images they act as a mask on the current paint
1151 vgTranslate(command.x, command.y);
1152 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1153 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1154 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
1155 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1156 vgScale(aspect_correction, 1.f);
1157 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1158 vgGetMatrix(save_matrix2);
1159 vgScale(imagewidth, imageheight);
1163 //vgScale(720.f/((float)BACKBUFFER_WIDTH), 576.f/((float)BACKBUFFER_HEIGHT));
1164 float scalex = command.w / imagewidth;
1165 float scaley = command.h / imageheight;
1166 float tx = command.x;
1167 float ty = command.y;
1169 if (command.corner == TopLeftLimited)
1171 if (scalex != 0.f && scaley != 0.f)
1173 float imageaspect = imagewidth / imageheight;
1174 float boxaspect = command.w / command.h / aspect_correction;
1176 if (imageaspect > boxaspect)
1179 ty += (command.h - imageheight * scalex / aspect_correction) * 0.5f;
1184 tx += (command.w - imagewidth * scaley * aspect_correction) * 0.5f;
1189 if (scalex == 0.f && scaley == 0.f)
1191 scalex = aspect_correction;
1194 else if (scalex == 0.f)
1196 scalex = scaley * aspect_correction;
1198 else if (scaley == 0.f)
1200 scaley = scalex / aspect_correction;
1203 if (command.corner == BottomRight || command.corner == BottomLeft || command.corner == BottomMiddle)
1205 ty -= imageheight * scaley;
1208 if (command.corner == BottomRight || command.corner == TopRight)
1210 tx -= imagewidth * scalex;
1213 if (command.corner == BottomMiddle || command.corner == TopMiddle)
1215 tx -= imagewidth * scalex * 0.5f;
1218 vgTranslate(tx, ty);
1219 //vgScale(command.w/imagewidth,command.h/imageheight);
1220 vgScale(scalex, scaley);
1221 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1222 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1223 //LogNT::getInstance()->debug(TAG, "TVMedia Draw Image Scale {} {} {} {} {} {}",command.w,imagewidth,command.h,imageheight,scalex,scaley);
1227 //vgTranslate(200.f,500.f);
1228 //vgScale(100.f,100.f);
1230 vgDrawImage(static_cast<VGImage>(command.target.image));
1232 //LogNT::getInstance()->debug(TAG, "Draw Image {} {:#x} {} {} {} {} {:#x}",command.handle,command.target.image,command.x,command.y,command.w,command.h,
1236 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1237 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1238 vgLoadMatrix(save_matrix2);
1241 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
1243 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
1244 vgLoadMatrix(save_matrix);
1249 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1250 vgGetMatrix(save_matrix);
1251 vgSetPaint(static_cast<VGPaint>(command.handle), VG_FILL_PATH);
1252 vgSetPaint(static_cast<VGPaint>(command.handle), VG_STROKE_PATH);
1253 vgTranslate(command.x, command.y);
1254 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1255 vgGetMatrix(save_matrix2);
1256 unsigned int glyph_index = FT_Get_Char_Index(ft_face, command.target.textchar);
1257 vgScale(font_exp_x[glyph_index], font_height);
1259 VGfloat gori[] = {0., 0.};
1260 vgSetfv(VG_GLYPH_ORIGIN, 2, gori);
1262 vgDrawGlyph(vgfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1263 //vgDrawPath(std_paths[Rectangle],VG_FILL_PATH);
1264 /* LogNT::getInstance()->debug(TAG, "Draw Glyph {} {} {} {} {} {:#x}",command.handle,command.target.textchar,glyph_index,command.x,command.y,
1266 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1267 vgLoadMatrix(save_matrix);
1268 vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
1269 vgLoadMatrix(save_matrix2);
1271 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1276 cTeletextChar tchar;
1277 tchar.setInternal(command.target.ttchar);
1278 vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
1279 vgGetMatrix(save_matrix);
1280 enumTeletextColor ttforegcolour = tchar.GetFGColor();
1281 enumTeletextColor ttbackgcolour = tchar.GetBGColor();
1283 if (tchar.GetBoxedOut())
1285 ttforegcolour = ttcTransparent;
1286 ttbackgcolour = ttcTransparent;
1289 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL);
1290 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
1292 vgTranslate(command.x + command.w * 11.85f * 1.4f, command.y + command.h * 19.75f);
1293 VGfloat gori[] = {0., 0.};
1294 vgSetfv(VG_GLYPH_ORIGIN, 2, gori);
1296 vgScale(-1.4f, 2.f);
1297 unsigned int color = Surface::enumTeletextColorToCoulour(ttbackgcolour).rgba();
1298 color = color << 8 | (color & 0xff000000) >> 24;
1299 vgSetColor(vgttpaint, color);
1300 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_FILL_PATH);
1301 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_STROKE_PATH);
1302 cTeletextChar filled;
1303 filled.setInternal(0x187f);
1304 unsigned int glyph_index = loadTTchar(filled);
1305 vgDrawGlyph(vgttfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1307 color = Surface::enumTeletextColorToCoulour(ttforegcolour).rgba();
1308 color = color << 8 | (color & 0xff000000) >> 24;
1309 vgSetColor(vgttpaint, color);
1310 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_FILL_PATH);
1311 vgSetPaint(static_cast<VGPaint>(vgttpaint), VG_STROKE_PATH);
1312 glyph_index = loadTTchar(tchar);
1313 vgDrawGlyph(vgttfont, glyph_index, VG_FILL_PATH, VG_FALSE);
1315 /* LogNT::getInstance()->debug(TAG, "Draw TTchar {:#x} {:#x} {:#x} {:#x}",glyph_index,ttforegcolour,Surface::enumTeletextColorToCoulour(ttforegcolour).rgba(),
1316 vgGetColor(vgttpaint));*/
1318 vgLoadMatrix(save_matrix);
1319 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
1320 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
1321 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
1326 VGint coords[4] = {0, 0, 0, 0};
1327 coords[0] = ((command.x + clip_shift_x) * ((float)BACKBUFFER_WIDTH) / 720.f);
1328 coords[1] = ((576.f - command.y - clip_shift_y - command.h) * ((float)BACKBUFFER_HEIGHT) / 576.f);
1329 coords[2] = ((command.w - 1.f) * ((float)BACKBUFFER_WIDTH) / 720.f);
1330 coords[3] = ((command.h - 1.f) * ((float)BACKBUFFER_HEIGHT) / 576.f);
1331 vgSetiv(VG_SCISSOR_RECTS, 4, coords);
1333 if (command.w == 0.f && command.h == 0.f)
1334 vgSeti(VG_SCISSORING, VG_FALSE);
1336 vgSeti(VG_SCISSORING, VG_TRUE);
1340 case DrawImageLoading:
1346 //int imcount=0;// this is debug code and should not go into release
1347 unsigned int OsdOpenVG::handleOpenVGCommand(OpenVGCommand& command)
1349 switch (command.task)
1351 case OVGreplacefont:
1353 vgDestroyFont(vgfont);
1357 case OVGdestroyImageRef: //imcount--;
1359 //LogNT::getInstance()->debug(TAG, "TVMedia Draw Image Destroy {:#x} {}",command.param1,imcount);
1360 vgDestroyImage(static_cast<VGImage>(command.param1));
1363 case OVGdestroyPaint:
1365 //LogNT::getInstance()->debug(TAG, "Draw Paint Destroy {}",command.param1);
1366 vgDestroyPaint(static_cast<VGPaint>(command.param1));
1369 case OVGcreateImagePalette: //imcount++;
1371 VGImage input = vgCreateImage(VG_A_8, command.param1, command.param2,
1372 VG_IMAGE_QUALITY_NONANTIALIASED |
1373 VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER);
1374 //LogNT::getInstance()->debug(TAG, "Draw create palette {} {} {:#x} {}",command.param1,command.param2,vgGetError(),input);
1375 vgImageSubData(input, command.data, command.param1,
1376 VG_A_8, 0, 0, command.param1, command.param2); // upload palettized image data
1377 VGImage handle = vgCreateImage(VG_sRGBA_8888, command.param1, command.param2,
1378 VG_IMAGE_QUALITY_NONANTIALIASED |
1379 VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER);
1380 VGuint* palette = static_cast<VGuint*>(malloc(256 * sizeof(VGuint)));
1381 const VGuint* in_palette = static_cast<const VGuint*>(command.data2);
1383 for (int i = 0; i < 256; i++)
1385 VGuint color = in_palette[i];
1386 palette[i] = color << 8 | (color & 0xff000000) >> 24;
1389 vgLookupSingle(handle, input, palette, VG_ALPHA, VG_FALSE, VG_FALSE);
1391 vgDestroyImage(input);
1395 case OVGcreateMonoBitmap: //imcount++;
1397 VGImage handle = vgCreateImage(VG_A_1, command.param1, command.param2,
1398 VG_IMAGE_QUALITY_FASTER);
1399 //LogNT::getInstance()->debug(TAG, "Draw create mono {} {} {:#x} {}",command.param1,command.param2,vgGetError(),handle);
1400 unsigned int buffer_len = (command.param1 * command.param2) >> 3;
1401 unsigned char* buffer = static_cast<unsigned char*>(malloc(buffer_len));
1402 unsigned char* r_buffer1 = buffer;
1403 const unsigned char* r_buffer2 = static_cast<const unsigned char*>(command.data);
1404 unsigned char* buffer_end = buffer + buffer_len;
1406 while (r_buffer1 != buffer_end)
1408 unsigned char byte = *r_buffer2;
1409 *r_buffer1 = ((byte * 0x0802LU & 0x22110LU) | (byte * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
1410 r_buffer1++; r_buffer2++;
1413 vgImageSubData(handle, buffer, command.param1 >> 3, VG_A_1, 0, 0, command.param1, command.param2);
1415 // LogNT::getInstance()->debug(TAG, "Draw create mono2 {} {} {:#x} {}",command.param1,command.param2,vgGetError(),handle);
1418 /*case OVGcreateImageFile: {
1421 Image *imagefile=(Image*)command.data;
1423 imagefile->write(&imageblob,"RGBA");
1425 handle=vgCreateImage(VG_sXBGR_8888,imagefile->columns(),imagefile->rows(),
1426 VG_IMAGE_QUALITY_BETTER);
1427 //LogNT::getInstance()->debug(TAG, "Draw create image details {} {} {:#x} mark1",imagefile->columns(),imagefile->rows(),(unsigned int*)imageblob.data());
1428 vgImageSubData(handle,imageblob.data(),imagefile->columns()*4,
1429 VG_sXBGR_8888,0,0,imagefile->columns(),imagefile->rows());
1430 //LogNT::getInstance()->debug(TAG, "Draw create image details {} {} {:#x} mark2",imagefile->columns(),imagefile->rows(),(unsigned int*)imageblob.data());
1432 }catch( Exception &error_ )
1434 LogNT::getInstance()->debug(TAG, "Libmagick hT: {}",error_.what());
1439 //LogNT::getInstance()->debug(TAG, "Draw create file {} {} {:#x} {}",command.param1,command.param2,vgGetError(),handle);
1442 case OVGcreateImageMemory: //imcount++;
1444 const PictureInfo* info = static_cast<const PictureInfo*>(command.data);
1446 //LogNT::getInstance()->debug(TAG, "TVMedia OVGcreateImageMemory {}",imcount);
1447 handle = vgCreateImage(VG_sABGR_8888, info->width, info->height, VG_IMAGE_QUALITY_BETTER);
1448 vgImageSubData(handle, info->image, info->width * 4,
1449 VG_sABGR_8888, 0, 0, info->width, info->height);
1450 info->decoder->freeReference(info->reference);
1452 bool static_image = true;
1454 if (info->lindex & 0xffffffff) static_image = false;
1456 Message* m = new Message();
1457 // We have a pictures! send a message to ourself, to switch to gui thread
1460 m->data = reinterpret_cast<void*>(handle);
1464 m->message = Message::NEW_PICTURE;
1465 m->tag = info->lindex;
1469 m->message = Message::NEW_PICTURE_STATIC;
1470 m->tag = info->lindex >> 32LL;
1472 MessageQueue::getInstance()->postMessage(m);
1477 case OVGcreateEGLImage: //imcount++;
1479 PictureInfo* info = const_cast<PictureInfo*>(static_cast<const PictureInfo*>(command.data));
1482 handle = vgCreateImage(VG_sABGR_8888, info->width, info->height, VG_IMAGE_QUALITY_BETTER);
1483 // LogNT::getInstance()->debug(TAG, "TVMedia OVGcreateEGLImage {} {} {:#x} {}",info->width,info->height, handle,imcount);
1485 info->handle = handle;
1486 info->reference = eglCreateImageKHR(egl_display, egl_context, EGL_VG_PARENT_IMAGE_KHR, reinterpret_cast<EGLClientBuffer>(handle), NULL);
1487 if (info->reference) return true;
1489 LogNT::getInstance()->debug(TAG, "TVMedia OVGcreateEGLImage {} {} {:#x} Fail!", info->width, info->height, handle);
1490 if (handle) vgDestroyImage(handle);
1493 case OVGreadyEGLImage:
1495 PictureInfo* info = const_cast<PictureInfo*>(static_cast<const PictureInfo*>(command.data));
1496 eglDestroyImageKHR(egl_display, info->reference);
1497 bool static_image = true;
1499 if (info->lindex & 0xffffffff) static_image = false;
1501 Message* m = new Message();
1504 m->data = reinterpret_cast<void*>(info->handle);
1508 m->message = Message::NEW_PICTURE;
1509 m->tag = info->lindex;
1513 m->message = Message::NEW_PICTURE_STATIC;
1514 m->tag = info->lindex >> 32LL;
1516 MessageQueue::getInstance()->postMessage(m); // inform command about new picture
1521 case OVGcreateColorRef:
1524 handle = vgCreatePaint();
1525 const DrawStyle* style = static_cast<const DrawStyle*>(command.data);
1529 case DrawStyle::Color:
1531 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
1532 vgSetColor(handle, command.param1);
1534 //rgba = vgGetColor((VGPaint)handle);
1535 //LogNT::getInstance()->debug(TAG, "Draw Paint {} {:#x} {:#x}",handle,command.param1,rgba);
1538 case DrawStyle::GradientLinear:
1540 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
1541 VGfloat params[] = {style->x1, style->y1, style->x2, style->y2, style->r};
1542 //LogNT::getInstance()->debug(TAG, "Draw Gradient {} {} {} {} {}",handle,params[0],params[1],params[2],params[3]);
1543 vgSetParameterfv(handle, VG_PAINT_LINEAR_GRADIENT, 4, params);
1546 case DrawStyle::GradientRadial:
1548 vgSetParameteri(handle, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
1549 VGfloat params[] = {style->x1, style->y1, style->x2, style->y2, style->r};
1550 vgSetParameterfv(handle, VG_PAINT_RADIAL_GRADIENT, 5, params);
1555 if (style->ft == DrawStyle::GradientLinear || style->ft == DrawStyle::GradientRadial)
1557 VGfloat colorramp[5 * 5];
1558 colorramp[0 + 0 * 5] = 0.f;
1559 colorramp[1 + 0 * 5] = static_cast<float>(style->red) / 255;
1560 colorramp[2 + 0 * 5] = static_cast<float>(style->green) / 255;
1561 colorramp[3 + 0 * 5] = static_cast<float>(style->blue) / 255;
1562 colorramp[4 + 0 * 5] = static_cast<float>(style->alpha) / 255;
1564 for (int i = 0; i < (style->num_colors - 1); i++)
1566 colorramp[0 + (i + 1) * 5] = style->grad_pos[i];
1567 colorramp[1 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].red) / 255.f;
1568 colorramp[2 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].green) / 255.f;
1569 colorramp[3 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].blue) / 255.f;
1570 colorramp[4 + (i + 1) * 5] = static_cast<float>(style->grad_col[i].alpha) / 255.f;
1573 colorramp[0 + (style->num_colors) * 5] = 1.f;
1574 colorramp[1 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].red) / 255.f;
1575 colorramp[2 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].green) / 255.f;
1576 colorramp[3 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].blue) / 255.f;
1577 colorramp[4 + (style->num_colors) * 5] = static_cast<float>(style->grad_col[style->num_colors - 1].alpha) / 255.f;
1578 vgSetParameteri(handle, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_REFLECT);
1579 vgSetParameteri(handle, VG_PAINT_COLOR_RAMP_PREMULTIPLIED, VG_FALSE);
1580 vgSetParameterfv(handle, VG_PAINT_COLOR_RAMP_STOPS, 5 + (style->num_colors) * 5, colorramp);
1586 case OVGimageUploadLine:
1593 void OsdOpenVG::destroyImageRef(VectorHandleImage handle)
1595 struct OpenVGCommand comm;
1596 comm.task = OVGdestroyImageRef;
1597 comm.param1 = handle;
1598 putOpenVGCommand(comm, false);
1601 bool OsdOpenVG::getStaticImageData(unsigned int static_id, UCHAR** userdata, ULONG* length)
1603 if (sa_MAX > static_id)
1605 *userdata = static_artwork_begin[static_id];
1606 *length = static_artwork_end[static_id] - static_artwork_begin[static_id];
1615 void OsdOpenVG::createPicture(struct PictureInfo& pict_inf)
1617 struct OpenVGCommand comm;
1618 LogNT::getInstance()->debug(TAG, "TVMedia Create Picture {}", pict_inf.type);
1620 if (pict_inf.type == PictureInfo::RGBAMemBlock)
1622 comm.task = OVGcreateImageMemory;
1623 comm.data = new PictureInfo(pict_inf);
1624 putOpenVGCommand(comm, false);
1626 else if (pict_inf.type == PictureInfo::EGLImage)
1628 comm.task = OVGreadyEGLImage;
1629 comm.data = new PictureInfo(pict_inf);
1630 putOpenVGCommand(comm, false);
1635 pict_inf.decoder->freeReference(pict_inf.reference);
1639 bool OsdOpenVG::getEGLPicture(struct OsdVector::PictureInfo& info, EGLDisplay* display)
1641 struct OpenVGCommand comm;
1642 info.type = PictureInfo::EGLImage;
1643 comm.task = OVGcreateEGLImage;
1645 *display = egl_display;
1646 return putOpenVGCommand(comm, true);
1649 VectorHandleImage OsdOpenVG::createMonoBitmap(void* base, int width, int height)
1651 struct OpenVGCommand comm;
1652 comm.task = OVGcreateMonoBitmap;
1653 comm.param1 = width;
1654 comm.param2 = height;
1656 return putOpenVGCommand(comm, true);
1659 VectorHandleImage OsdOpenVG::createImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data)
1661 struct OpenVGCommand comm;
1662 comm.task = OVGcreateImagePalette;
1663 comm.param1 = width;
1664 comm.param2 = height;
1665 comm.data = image_data;
1666 comm.data2 = palette_data;
1667 return putOpenVGCommand(comm, true);
1670 void OsdOpenVG::destroyDrawStyleHandle(VectorHandle index)
1672 struct OpenVGCommand comm;
1673 comm.task = OVGdestroyPaint;
1674 comm.param1 = index;
1675 putOpenVGCommand(comm, false);
1678 VectorHandle OsdOpenVG::createDrawStyleHandle(const DrawStyle& c)
1680 unsigned int col = c.rgba();
1681 struct OpenVGCommand comm;
1682 comm.task = OVGcreateColorRef;
1683 comm.param1 = col << 8 | (col & 0xff000000) >> 24;
1685 return putOpenVGCommand(comm, true);