]> git.vomp.tv Git - vompclient.git/commitdiff
OsdOpenVG: Group all thread/mutex using methods together
authorChris Tallon <chris@vomp.tv>
Wed, 20 May 2020 13:51:59 +0000 (14:51 +0100)
committerChris Tallon <chris@vomp.tv>
Wed, 20 May 2020 13:51:59 +0000 (14:51 +0100)
osdopenvg.cc

index ac2bd0db764ea6d4296c30065d111b197d2403ad..f867063b8db630a871d3093af4bbe2f6a5a6c5b6 100644 (file)
@@ -17,7 +17,6 @@
     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-#include <stdio.h>  // really?
 #include <chrono>
 #include <sys/syscall.h>
 #include <fontconfig/fontconfig.h>
@@ -290,7 +289,7 @@ int OsdOpenVG::init()
   eglSwapInterval(egl_display, 1);
 
   Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out 1%d", syscall(SYS_gettid));
-  eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
+  eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
   //Now we will create the Screen
   initted = true; // must set this here or create surface won't work
 
@@ -310,123 +309,6 @@ int OsdOpenVG::init()
   return 1;
 }
 
-void OsdOpenVG::updateBackgroundColor(DrawStyle bg)
-{
-  unsigned int color[16 * 16];
-
-  if (!bcm_backres) return;
-
-  VC_RECT_T src_rect_im = {0, 0, 16, 16};
-
-  if (bg.ft != DrawStyle::GradientLinear)
-  {
-    bg.grad_col[0] = bg;
-  }
-
-  //memset(color,0xFF,sizeof(unsigned int)*4*8);
-  for (int j = 0; j < 16; j++)
-  {
-    int helpr = (((15 - j) * bg.red) + (j * bg.grad_col[0].red)) / 15;
-    int helpb = (((15 - j) * bg.blue) + (j * bg.grad_col[0].blue)) / 15;
-    int helpg = (((15 - j) * bg.green) + (j * bg.grad_col[0].green)) / 15;
-    //unsigned int cur_col=help | (help<< 8)  | (help<< 16)  | (0xFF<< 24);
-    unsigned int cur_col = helpr  | (helpg << (8))  | (helpb << (16))  | (0xFF << (24));
-
-    for (int i = 0; i < 16; i++)
-    {
-      color[i + 16 * j] = cur_col;
-    }
-  }
-
-  vc_dispmanx_resource_write_data(bcm_backres, VC_IMAGE_RGBX32, 16 * 4, color, &src_rect_im);
-}
-
-void OsdOpenVG::getScreenSize(int& width, int& height)
-{
-  width = BACKBUFFER_WIDTH;
-  height = BACKBUFFER_HEIGHT;
-}
-
-void OsdOpenVG::getRealScreenSize(int& width, int& height)
-{
-  width = display_width;
-  height = display_height;
-}
-
-bool OsdOpenVG::screenShot(void* buffer, int width, int height, bool osd /*include osd*/)
-{
-  if (!initted) return false;
-
-  if (!buffer) return false;
-
-  DISPMANX_RESOURCE_HANDLE_T res;
-  DISPMANX_DISPLAY_HANDLE_T display;
-
-  uint32_t image_ptr;
-  VC_RECT_T rect;
-  res = vc_dispmanx_resource_create(VC_IMAGE_RGBA32, width, height, &image_ptr);
-  display = vc_dispmanx_display_open(0);
-
-  if (!osd)
-  {
-    vc_dispmanx_snapshot(display, res,
-                         static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_NO_RGB | DISPMANX_SNAPSHOT_FILL/*|DISPMANX_SNAPSHOT_PACK*/));
-  }
-  else
-  {
-    vc_dispmanx_snapshot(display, res,
-                         static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_FILL));
-  }
-
-  vc_dispmanx_rect_set(&rect, 0, 0, width, height);
-  vc_dispmanx_resource_read_data(res, &rect, buffer, width * 4);
-  vc_dispmanx_resource_delete(res);
-  vc_dispmanx_display_close(display);
-  return true;
-}
-
-void OsdOpenVG::initPaths()
-{
-  VGPath current;
-  current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
-                         VG_PATH_DATATYPE_F, 1.f, 0.f,
-                         0, 0, VG_PATH_CAPABILITY_ALL);
-
-  vguLine(current, 0.f, 0.f, 1.f, 0.f);
-  // HorzLine
-  std_paths[PIHorzLine] = current;
-
-  current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
-                         VG_PATH_DATATYPE_F, 1.f, 0.f,
-                         0, 0, VG_PATH_CAPABILITY_ALL);
-  vguLine(current, 0.f, 0.f, 0.f, 1.f);
-  // VertLine
-  std_paths[PIVertLine] = current;
-
-  current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
-                         VG_PATH_DATATYPE_F, 1.f, 0.f,
-                         0, 0, VG_PATH_CAPABILITY_ALL);
-  //vguRect(current,0.f,0.f,1.f,1.f);
-  vguRect(current, 0.f, 0.f, 1.f, 1.f);
-  // Rectabgle
-  std_paths[PIRectangle] = current;
-
-  current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
-                         VG_PATH_DATATYPE_F, 1.f, 0.f,
-                         0, 0, 0);
-  vguEllipse(current, 0.f, 0.f, 1.f, 1.f);
-  // Point
-  std_paths[PIPoint] = current;
-}
-
-void OsdOpenVG::destroyPaths()
-{
-  vgDestroyPath(std_paths[PIHorzLine]);
-  vgDestroyPath(std_paths[PIVertLine]);
-  vgDestroyPath(std_paths[PIRectangle]);
-  vgDestroyPath(std_paths[PIPoint]);
-}
-
 int OsdOpenVG::stopUpdate()
 {
   threadStop();
@@ -434,43 +316,6 @@ int OsdOpenVG::stopUpdate()
   return 1;
 }
 
-/*
-void OsdOpenVG::purgeAllReferences()
-{
-       images_ref.clear();
-       drawstyleHandlesRefCounts.clear(); // remove all references
-
-
-       map<void *,ImageIndex>::iterator mitty=monobitmaps.begin();
-       while (mitty!=monobitmaps.end()) {
-               vgDestroyImage((VGImage)(*mitty).second);
-               mitty++;
-       }
-       monobitmaps.clear();
-
-       / *map<string,ImageIndex>::iterator jitty=jpegs.begin();
-       while (jitty!=jpegs.end()) {
-               vgDestroyImage((VGImage)(*jitty).second);
-               jitty++;
-       }
-       jpegs.clear();* /
-
-       map<TVMediaInfo,ImageIndex>::iterator titty=tvmedias.begin();
-       while (titty!=tvmedias.end()) {
-               vgDestroyImage((VGImage)(*titty).second);
-               titty++;
-       }
-       tvmedias.clear();
-
-       map<pair<Colour*,unsigned int>,unsigned int>::iterator sitty=drawstyleHandles.begin();
-       while (sitty!=drawstyleHandles.end()) {
-               vgDestroyPaint((VGPaint)(*sitty).second);
-               sitty++;
-       }
-       drawstyleHandles.clear();
-
-}*/
-
 int OsdOpenVG::shutdown()
 {
   reader.shutdown();
@@ -516,7 +361,7 @@ int OsdOpenVG::shutdown()
   vgClear(0, 0, BACKBUFFER_WIDTH, BACKBUFFER_HEIGHT);
   eglSwapBuffers(egl_display, egl_surface);
   Log::getInstance()->log("OSD", Log::DEBUG, "Making egl current out final");
-  eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
+  eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 
   if (eglDestroySurface(egl_display, egl_surface) == EGL_FALSE)
   {
@@ -528,7 +373,7 @@ int OsdOpenVG::shutdown()
     Log::getInstance()->log("OSD", Log::ERR, "eglDestroyContext failed %x", eglGetError());
   }
 
-  if (eglTerminate(egl_display ) == EGL_FALSE)
+  if (eglTerminate(egl_display) == EGL_FALSE)
   {
     Log::getInstance()->log("OSD", Log::ERR, "eglTerminate failed %x", eglGetError());
   }
@@ -593,7 +438,7 @@ void OsdOpenVG::threadMethod()
 
     if (!threadIsActive())
     {
-      if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ) == EGL_FALSE)
+      if (eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) == EGL_FALSE)
       {
         Log::getInstance()->log("OSD", Log::WARN, "Making egl Current out thread failed");
       }
@@ -622,6 +467,89 @@ void OsdOpenVG::threadMethod()
   eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 }
 
+unsigned int OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm, bool wait)
+{
+  taskmutex.lock();
+
+  if (wait)
+    comm.id = wait_id++;
+  else
+    comm.id = 0; // we are not waiting
+
+  vgcommands.push_back(comm);
+  taskmutex.unlock();
+
+  threadSignal();
+
+  if (!wait) return 0;
+
+  while(1)
+  {
+    // Is there a response now?
+    taskmutex.lock();
+    for (auto& vgresponse : vgresponses)
+    {
+      if (vgresponse.id == comm.id)
+      {
+        UINT resp = vgresponse.result;
+        taskmutex.unlock();
+        return resp;
+      }
+    }
+    // No.
+    taskmutex.unlock();
+
+    std::unique_lock<std::mutex> ul(vgTaskSignalMutex);
+    vgTaskSignal.wait_for(ul, std::chrono::milliseconds(100));
+    ul.unlock();
+  }
+}
+
+bool OsdOpenVG::processOpenVGCommands()
+{
+  bool worked = false;
+  taskmutex.lock();
+  vgmutex.lock();
+
+  while (vgcommands.size() > 0)
+  {
+    OpenVGCommand comm = vgcommands.front();
+    vgcommands.pop_front();
+    taskmutex.unlock();
+
+    OpenVGResponse resp;
+    resp.result = handleOpenVGCommand(comm);
+    resp.id = comm.id;
+    taskmutex.lock();
+
+    if (comm.id)
+    {
+      vgresponses.push_back(resp);
+    }
+
+    taskmutex.unlock();
+    vgmutex.unlock();
+
+    /* Getting rid of Signal class. As with VideoOMX, just replicate what Signal did here
+     * and figure out if any of this can be simplified later. e.g. taskmutex sounds
+     * like it should be the mutex being used. 3 mutexes here???
+     */
+
+    vgTaskSignalMutex.lock();
+    vgTaskSignal.notify_one();
+    vgTaskSignalMutex.unlock();
+
+    taskmutex.lock();
+    vgmutex.lock();
+    worked = true;
+  }
+
+  taskmutex.unlock();
+  vgmutex.unlock();
+
+  return worked;
+}
+
 void OsdOpenVG::InternalRendering()
 {
   vgmutex.lock();
@@ -641,6 +569,162 @@ void OsdOpenVG::InternalRendering()
   vgmutex.unlock();
 }
 
+// --------------------------------------------------------------------------------------------------------------------------
+
+/*
+void OsdOpenVG::purgeAllReferences()
+{
+       images_ref.clear();
+       drawstyleHandlesRefCounts.clear(); // remove all references
+
+
+       map<void *,ImageIndex>::iterator mitty=monobitmaps.begin();
+       while (mitty!=monobitmaps.end()) {
+               vgDestroyImage((VGImage)(*mitty).second);
+               mitty++;
+       }
+       monobitmaps.clear();
+
+       / *map<string,ImageIndex>::iterator jitty=jpegs.begin();
+       while (jitty!=jpegs.end()) {
+               vgDestroyImage((VGImage)(*jitty).second);
+               jitty++;
+       }
+       jpegs.clear();* /
+
+       map<TVMediaInfo,ImageIndex>::iterator titty=tvmedias.begin();
+       while (titty!=tvmedias.end()) {
+               vgDestroyImage((VGImage)(*titty).second);
+               titty++;
+       }
+       tvmedias.clear();
+
+       map<pair<Colour*,unsigned int>,unsigned int>::iterator sitty=drawstyleHandles.begin();
+       while (sitty!=drawstyleHandles.end()) {
+               vgDestroyPaint((VGPaint)(*sitty).second);
+               sitty++;
+       }
+       drawstyleHandles.clear();
+
+}*/
+
+void OsdOpenVG::updateBackgroundColor(DrawStyle bg)
+{
+  unsigned int color[16 * 16];
+
+  if (!bcm_backres) return;
+
+  VC_RECT_T src_rect_im = {0, 0, 16, 16};
+
+  if (bg.ft != DrawStyle::GradientLinear)
+  {
+    bg.grad_col[0] = bg;
+  }
+
+  //memset(color,0xFF,sizeof(unsigned int)*4*8);
+  for (int j = 0; j < 16; j++)
+  {
+    int helpr = (((15 - j) * bg.red) + (j * bg.grad_col[0].red)) / 15;
+    int helpb = (((15 - j) * bg.blue) + (j * bg.grad_col[0].blue)) / 15;
+    int helpg = (((15 - j) * bg.green) + (j * bg.grad_col[0].green)) / 15;
+    //unsigned int cur_col=help | (help<< 8)  | (help<< 16)  | (0xFF<< 24);
+    unsigned int cur_col = helpr  | (helpg << (8))  | (helpb << (16))  | (0xFF << (24));
+
+    for (int i = 0; i < 16; i++)
+    {
+      color[i + 16 * j] = cur_col;
+    }
+  }
+
+  vc_dispmanx_resource_write_data(bcm_backres, VC_IMAGE_RGBX32, 16 * 4, color, &src_rect_im);
+}
+
+void OsdOpenVG::getScreenSize(int& width, int& height)
+{
+  width = BACKBUFFER_WIDTH;
+  height = BACKBUFFER_HEIGHT;
+}
+
+void OsdOpenVG::getRealScreenSize(int& width, int& height)
+{
+  width = display_width;
+  height = display_height;
+}
+
+bool OsdOpenVG::screenShot(void* buffer, int width, int height, bool osd /*include osd*/)
+{
+  if (!initted) return false;
+
+  if (!buffer) return false;
+
+  DISPMANX_RESOURCE_HANDLE_T res;
+  DISPMANX_DISPLAY_HANDLE_T display;
+
+  uint32_t image_ptr;
+  VC_RECT_T rect;
+  res = vc_dispmanx_resource_create(VC_IMAGE_RGBA32, width, height, &image_ptr);
+  display = vc_dispmanx_display_open(0);
+
+  if (!osd)
+  {
+    vc_dispmanx_snapshot(display, res,
+                         static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_NO_RGB | DISPMANX_SNAPSHOT_FILL/*|DISPMANX_SNAPSHOT_PACK*/));
+  }
+  else
+  {
+    vc_dispmanx_snapshot(display, res,
+                         static_cast<DISPMANX_TRANSFORM_T>(DISPMANX_SNAPSHOT_FILL));
+  }
+
+  vc_dispmanx_rect_set(&rect, 0, 0, width, height);
+  vc_dispmanx_resource_read_data(res, &rect, buffer, width * 4);
+  vc_dispmanx_resource_delete(res);
+  vc_dispmanx_display_close(display);
+  return true;
+}
+
+void OsdOpenVG::initPaths()
+{
+  VGPath current;
+  current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+                         VG_PATH_DATATYPE_F, 1.f, 0.f,
+                         0, 0, VG_PATH_CAPABILITY_ALL);
+
+  vguLine(current, 0.f, 0.f, 1.f, 0.f);
+  // HorzLine
+  std_paths[PIHorzLine] = current;
+
+  current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+                         VG_PATH_DATATYPE_F, 1.f, 0.f,
+                         0, 0, VG_PATH_CAPABILITY_ALL);
+  vguLine(current, 0.f, 0.f, 0.f, 1.f);
+  // VertLine
+  std_paths[PIVertLine] = current;
+
+  current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+                         VG_PATH_DATATYPE_F, 1.f, 0.f,
+                         0, 0, VG_PATH_CAPABILITY_ALL);
+  //vguRect(current,0.f,0.f,1.f,1.f);
+  vguRect(current, 0.f, 0.f, 1.f, 1.f);
+  // Rectabgle
+  std_paths[PIRectangle] = current;
+
+  current = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+                         VG_PATH_DATATYPE_F, 1.f, 0.f,
+                         0, 0, 0);
+  vguEllipse(current, 0.f, 0.f, 1.f, 1.f);
+  // Point
+  std_paths[PIPoint] = current;
+}
+
+void OsdOpenVG::destroyPaths()
+{
+  vgDestroyPath(std_paths[PIHorzLine]);
+  vgDestroyPath(std_paths[PIVertLine]);
+  vgDestroyPath(std_paths[PIRectangle]);
+  vgDestroyPath(std_paths[PIPoint]);
+}
+
 /*font stuff*/
 
 float OsdOpenVG::getFontHeight()
@@ -1464,89 +1548,6 @@ unsigned int OsdOpenVG::handleOpenVGCommand(OpenVGCommand& command)
   return 0;
 }
 
-bool OsdOpenVG::processOpenVGCommands()
-{
-  bool worked = false;
-  taskmutex.lock();
-  vgmutex.lock();
-
-  while (vgcommands.size() > 0)
-  {
-    OpenVGCommand comm = vgcommands.front();
-    vgcommands.pop_front();
-    taskmutex.unlock();
-
-    OpenVGResponse resp;
-    resp.result = handleOpenVGCommand(comm);
-    resp.id = comm.id;
-    taskmutex.lock();
-
-    if (comm.id)
-    {
-      vgresponses.push_back(resp);
-    }
-
-    taskmutex.unlock();
-    vgmutex.unlock();
-
-    /* Getting rid of Signal class. As with VideoOMX, just replicate what Signal did here
-     * and figure out if any of this can be simplified later. e.g. taskmutex sounds
-     * like it should be the mutex being used. 3 mutexes here???
-     */
-
-    vgTaskSignalMutex.lock();
-    vgTaskSignal.notify_one();
-    vgTaskSignalMutex.unlock();
-
-    taskmutex.lock();
-    vgmutex.lock();
-    worked = true;
-  }
-
-  taskmutex.unlock();
-  vgmutex.unlock();
-
-  return worked;
-}
-
-unsigned int OsdOpenVG::putOpenVGCommand(OpenVGCommand& comm, bool wait)
-{
-  taskmutex.lock();
-
-  if (wait)
-    comm.id = wait_id++;
-  else
-    comm.id = 0; // we are not waiting
-
-  vgcommands.push_back(comm);
-  taskmutex.unlock();
-
-  threadSignal();
-
-  if (!wait) return 0;
-
-  while(1)
-  {
-    // Is there a response now?
-    taskmutex.lock();
-    for (auto& vgresponse : vgresponses)
-    {
-      if (vgresponse.id == comm.id)
-      {
-        UINT resp = vgresponse.result;
-        taskmutex.unlock();
-        return resp;
-      }
-    }
-    // No.
-    taskmutex.unlock();
-
-    std::unique_lock<std::mutex> ul(vgTaskSignalMutex);
-    vgTaskSignal.wait_for(ul, std::chrono::milliseconds(100));
-    ul.unlock();
-  }
-}
-
 void OsdOpenVG::destroyImageRef(ImageIndex index)
 {
   struct OpenVGCommand comm;