Skip to content
This repository
Browse code

bluray: factor out overlay functions to reduce code duplication

  • Loading branch information...
commit b8c297c867a7b10c7a352ef5ada9a26c48ae893e 1 parent 594f5a8
Joakim Plate authored February 06, 2013 elupus committed February 11, 2013
210  xbmc/cores/dvdplayer/DVDInputStreams/DVDInputStreamBluray.cpp
@@ -652,16 +652,93 @@ static uint32_t build_rgba(const BD_PG_PALETTE_ENTRY &e)
652 652
        | (uint32_t)clamp(b) << PIXEL_BSHIFT;
653 653
 }
654 654
 
  655
+void CDVDInputStreamBluray::OverlayClose()
  656
+{
  657
+#if(BD_OVERLAY_INTERFACE_VERSION >= 2)
  658
+  for(unsigned i = 0; i < 2; ++i)
  659
+    m_planes[i].o.clear();
  660
+  CDVDOverlayGroup* group   = new CDVDOverlayGroup();
  661
+  group->bForced = true;
  662
+  m_player->OnDVDNavResult(group, 0);
  663
+#endif
  664
+}
  665
+
  666
+void CDVDInputStreamBluray::OverlayInit(SPlane& plane, int w, int h)
  667
+{
  668
+#if(BD_OVERLAY_INTERFACE_VERSION >= 2)
  669
+  plane.o.clear();
  670
+  plane.w = w;
  671
+  plane.h = h;
  672
+#endif
  673
+}
  674
+
  675
+void CDVDInputStreamBluray::OverlayClear(SPlane& plane, int x, int y, int w, int h)
  676
+{
  677
+#if(BD_OVERLAY_INTERFACE_VERSION >= 2)
  678
+  CRect ovr(x
  679
+          , y
  680
+          , x + w
  681
+          , y + h);
  682
+
  683
+  /* fixup existing overlays */
  684
+  for(SOverlays::iterator it = plane.o.begin(); it != plane.o.end();)
  685
+  {
  686
+    CRect old((*it)->x
  687
+            , (*it)->y
  688
+            , (*it)->x + (*it)->width
  689
+            , (*it)->y + (*it)->height);
  690
+
  691
+    vector<CRect> rem = old.SubtractRect(ovr);
  692
+
  693
+    /* if no overlap we are done */
  694
+    if(rem.size() == 1 && !(rem[0] != old))
  695
+    {
  696
+      it++;
  697
+      continue;
  698
+    }
  699
+
  700
+    SOverlays add;
  701
+    for(vector<CRect>::iterator itr = rem.begin(); itr != rem.end(); ++itr)
  702
+    {
  703
+      SOverlay overlay(new CDVDOverlayImage(*(*it)
  704
+                                            , itr->x1
  705
+                                            , itr->y1
  706
+                                            , itr->Width()
  707
+                                            , itr->Height())
  708
+                    , std::ptr_fun(CDVDOverlay::Release));
  709
+      add.push_back(overlay);
  710
+    }
  711
+
  712
+    it = plane.o.erase(it);
  713
+    plane.o.insert(it, add.begin(), add.end());
  714
+  }
  715
+#endif
  716
+}
  717
+
  718
+void CDVDInputStreamBluray::OverlayFlush(int64_t pts)
  719
+{
  720
+#if(BD_OVERLAY_INTERFACE_VERSION >= 2)
  721
+  CDVDOverlayGroup* group   = new CDVDOverlayGroup();
  722
+  group->bForced       = true;
  723
+  group->iPTSStartTime = (double) pts;
  724
+  group->iPTSStopTime  = 0;
  725
+
  726
+  for(unsigned i = 0; i < 2; ++i)
  727
+  {
  728
+    for(SOverlays::iterator it = m_planes[i].o.begin(); it != m_planes[i].o.end(); ++it)
  729
+      group->m_overlays.push_back((*it)->Acquire());
  730
+  }
  731
+
  732
+  m_player->OnDVDNavResult(group, 0);
  733
+#endif
  734
+}
  735
+
655 736
 void CDVDInputStreamBluray::OverlayCallback(const BD_OVERLAY * const ov)
656 737
 {
657 738
 #if(BD_OVERLAY_INTERFACE_VERSION >= 2)
658 739
   if(ov == NULL || ov->cmd == BD_OVERLAY_CLOSE)
659 740
   {
660  
-    for(unsigned i = 0; i < 2; ++i)
661  
-      m_planes[i].o.clear();
662  
-    CDVDOverlayGroup* group   = new CDVDOverlayGroup();
663  
-    group->bForced = true;
664  
-    m_player->OnDVDNavResult(group, 0);
  741
+    OverlayClose();
665 742
     return;
666 743
   }
667 744
 
@@ -681,53 +758,14 @@ void CDVDInputStreamBluray::OverlayCallback(const BD_OVERLAY * const ov)
681 758
 
682 759
   if (ov->cmd == BD_OVERLAY_INIT)
683 760
   {
684  
-    plane.o.clear();
685  
-    plane.w = ov->w;
686  
-    plane.h = ov->h;
  761
+    OverlayInit(plane, ov->w, ov->h);
687 762
     return;
688 763
   }
689 764
 
690 765
   if (ov->cmd == BD_OVERLAY_DRAW
691 766
   ||  ov->cmd == BD_OVERLAY_WIPE)
692  
-  {
693  
-    CRect ovr(ov->x
694  
-            , ov->y
695  
-            , ov->x + ov->w
696  
-            , ov->y + ov->h);
  767
+    OverlayClear(plane, ov->x, ov->y, ov->w, ov->h);
697 768
 
698  
-    /* fixup existing overlays */
699  
-    for(SOverlays::iterator it = plane.o.begin(); it != plane.o.end();)
700  
-    {
701  
-      CRect old((*it)->x
702  
-              , (*it)->y
703  
-              , (*it)->x + (*it)->width
704  
-              , (*it)->y + (*it)->height);
705  
-
706  
-      vector<CRect> rem = old.SubtractRect(ovr);
707  
-
708  
-      /* if no overlap we are done */
709  
-      if(rem.size() == 1 && !(rem[0] != old))
710  
-      {
711  
-        it++;
712  
-        continue;
713  
-      }
714  
-
715  
-      SOverlays add;
716  
-      for(vector<CRect>::iterator itr = rem.begin(); itr != rem.end(); ++itr)
717  
-      {
718  
-        SOverlay overlay(new CDVDOverlayImage(*(*it)
719  
-                                              , itr->x1
720  
-                                              , itr->y1
721  
-                                              , itr->Width()
722  
-                                              , itr->Height())
723  
-                      , std::ptr_fun(CDVDOverlay::Release));
724  
-        add.push_back(overlay);
725  
-      }
726  
-
727  
-      it = plane.o.erase(it);
728  
-      plane.o.insert(it, add.begin(), add.end());
729  
-    }
730  
-  }
731 769
 
732 770
   /* uncompress and draw bitmap */
733 771
   if (ov->img && ov->cmd == BD_OVERLAY_DRAW)
@@ -763,20 +801,7 @@ void CDVDInputStreamBluray::OverlayCallback(const BD_OVERLAY * const ov)
763 801
   }
764 802
 
765 803
   if(ov->cmd == BD_OVERLAY_FLUSH)
766  
-  {
767  
-    CDVDOverlayGroup* group   = new CDVDOverlayGroup();
768  
-    group->bForced       = true;
769  
-    group->iPTSStartTime = (double) ov->pts;
770  
-    group->iPTSStopTime  = 0;
771  
-
772  
-    for(unsigned i = 0; i < 2; ++i)
773  
-    {
774  
-      for(SOverlays::iterator it = m_planes[i].o.begin(); it != m_planes[i].o.end(); ++it)
775  
-        group->m_overlays.push_back((*it)->Acquire());
776  
-    }
777  
-
778  
-    m_player->OnDVDNavResult(group, 0);
779  
-  }
  804
+    OverlayFlush(ov->pts);
780 805
 #endif
781 806
 }
782 807
 
@@ -785,11 +810,7 @@ void CDVDInputStreamBluray::OverlayCallbackARGB(const struct bd_argb_overlay_s *
785 810
 {
786 811
   if(ov == NULL || ov->cmd == BD_ARGB_OVERLAY_CLOSE)
787 812
   {
788  
-    for(unsigned i = 0; i < 2; ++i)
789  
-      m_planes[i].o.clear();
790  
-    CDVDOverlayGroup* group   = new CDVDOverlayGroup();
791  
-    group->bForced = true;
792  
-    m_player->OnDVDNavResult(group, 0);
  813
+    OverlayClose();
793 814
     return;
794 815
   }
795 816
 
@@ -803,52 +824,12 @@ void CDVDInputStreamBluray::OverlayCallbackARGB(const struct bd_argb_overlay_s *
803 824
 
804 825
   if (ov->cmd == BD_ARGB_OVERLAY_INIT)
805 826
   {
806  
-    plane.o.clear();
807  
-    plane.w = ov->w;
808  
-    plane.h = ov->h;
  827
+    OverlayInit(plane, ov->w, ov->h);
809 828
     return;
810 829
   }
811 830
 
812 831
   if (ov->cmd == BD_ARGB_OVERLAY_DRAW)
813  
-  {
814  
-    CRect ovr(ov->x
815  
-            , ov->y
816  
-            , ov->x + ov->w
817  
-            , ov->y + ov->h);
818  
-
819  
-    /* fixup existing overlays */
820  
-    for(SOverlays::iterator it = plane.o.begin(); it != plane.o.end();)
821  
-    {
822  
-      CRect old((*it)->x
823  
-              , (*it)->y
824  
-              , (*it)->x + (*it)->width
825  
-              , (*it)->y + (*it)->height);
826  
-
827  
-      vector<CRect> rem = old.SubtractRect(ovr);
828  
-
829  
-      /* if no overlap we are done */
830  
-      if(rem.size() == 1 && !(rem[0] != old))
831  
-      {
832  
-        it++;
833  
-        continue;
834  
-      }
835  
-
836  
-      SOverlays add;
837  
-      for(vector<CRect>::iterator itr = rem.begin(); itr != rem.end(); ++itr)
838  
-      {
839  
-        SOverlay overlay(new CDVDOverlayImage(*(*it)
840  
-                                              , itr->x1
841  
-                                              , itr->y1
842  
-                                              , itr->Width()
843  
-                                              , itr->Height())
844  
-                      , std::ptr_fun(CDVDOverlay::Release));
845  
-        add.push_back(overlay);
846  
-      }
847  
-
848  
-      it = plane.o.erase(it);
849  
-      plane.o.insert(it, add.begin(), add.end());
850  
-    }
851  
-  }
  832
+    OverlayClear(plane, ov->x, ov->y, ov->w, ov->h);
852 833
 
853 834
   /* uncompress and draw bitmap */
854 835
   if (ov->argb && ov->cmd == BD_ARGB_OVERLAY_DRAW)
@@ -874,20 +855,7 @@ void CDVDInputStreamBluray::OverlayCallbackARGB(const struct bd_argb_overlay_s *
874 855
   }
875 856
 
876 857
   if(ov->cmd == BD_ARGB_OVERLAY_FLUSH)
877  
-  {
878  
-    CDVDOverlayGroup* group   = new CDVDOverlayGroup();
879  
-    group->bForced       = true;
880  
-    group->iPTSStartTime = (double) ov->pts;
881  
-    group->iPTSStopTime  = 0;
882  
-
883  
-    for(unsigned i = 0; i < 2; ++i)
884  
-    {
885  
-      for(SOverlays::iterator it = m_planes[i].o.begin(); it != m_planes[i].o.end(); ++it)
886  
-        group->m_overlays.push_back((*it)->Acquire());
887  
-    }
888  
-
889  
-    m_player->OnDVDNavResult(group, 0);
890  
-  }
  858
+    OverlayFlush(ov->pts);
891 859
 }
892 860
 #endif
893 861
 
7  xbmc/cores/dvdplayer/DVDInputStreams/DVDInputStreamBluray.h
@@ -107,6 +107,13 @@ class CDVDInputStreamBluray
107 107
   void ProcessEvent();
108 108
 
109 109
 protected:
  110
+  struct SPlane;
  111
+
  112
+  void OverlayFlush(int64_t pts);
  113
+  void OverlayClose();
  114
+  void OverlayClear(SPlane& plane, int x, int y, int w, int h);
  115
+  void OverlayInit (SPlane& plane, int w, int h);
  116
+
110 117
   IDVDPlayer*   m_player;
111 118
   DllLibbluray *m_dll;
112 119
   BLURAY* m_bd;

0 notes on commit b8c297c

Please sign in to comment.
Something went wrong with that request. Please try again.