Merge branch 'bug_486_add_service_event_progress_to_servicelist'
[enigma2.git] / lib / gui / evideo.cpp
1 #include <lib/gui/evideo.h>
2 #include <lib/gui/ewidgetdesktop.h>
3
4 static ePtr<eTimer> fullsizeTimer;
5 static int pendingFullsize;
6
7 void setFullsize()
8 {
9         for (int decoder=0; decoder < 1; ++decoder)
10         {
11                 if (pendingFullsize & (1 << decoder))
12                 {
13                         for (int i=0; i<4; ++i)
14                         {
15                                 const char *targets[]={"left", "top", "width", "height"};
16                                 char filename[128];
17                                 snprintf(filename, 128, "/proc/stb/vmpeg/%d/dst_%s", decoder, targets[i]);
18                                 FILE *f = fopen(filename, "w");
19                                 if (!f)
20                                 {
21                                         eDebug("failed to open %s - %m", filename);
22                                         break;
23                                 }
24                                 fprintf(f, "%08x\n", 0);
25                                 fclose(f);
26                         }
27                         pendingFullsize &= ~(1 << decoder);
28                 }
29         }
30 }
31
32 eVideoWidget::eVideoWidget(eWidget *parent)
33         :eLabel(parent), m_fb_size(720, 576), m_state(0), m_decoder(1)
34 {
35         if (!fullsizeTimer)
36         {
37                 fullsizeTimer = eTimer::create(eApp);
38                 fullsizeTimer->timeout.connect(slot(setFullsize));
39         }
40         parent->setPositionNotifyChild(1);
41 //      setBackgroundColor(gRGB(0xFF000000));
42 }
43
44 int eVideoWidget::event(int event, void *data, void *data2)
45 {
46         switch (event)
47         {
48         case evtChangedPosition:
49         case evtParentChangedPosition:
50                 m_state &= ~1;
51                 updatePosition(!isVisible());
52                 break;
53         case evtChangedSize:
54                 m_state |= 2;
55                 updatePosition(!isVisible());
56                 break;
57         case evtParentVisibilityChanged:
58                 updatePosition(!isVisible());
59                 break;
60         }
61         return eLabel::event(event, data, data2);
62 }
63
64 eVideoWidget::~eVideoWidget()
65 {
66         updatePosition(1);
67 }
68
69 void eVideoWidget::setFBSize(eSize size)
70 {
71         m_fb_size = size;
72 }
73
74 void eVideoWidget::updatePosition(int disable)
75 {
76         if (!disable)
77                 m_state |= 4;
78
79         if (disable && !(m_state & 4))
80         {
81 //              eDebug("was not visible!");
82                 return;
83         }
84
85         if ((m_state & 2) != 2)
86         {
87 //              eDebug("no size!");
88                 return;
89         }
90
91 //      eDebug("position %d %d -> %d %d", position().x(), position().y(), size().width(), size().height());
92
93         eRect pos(0,0,0,0);
94         if (!disable)
95                 pos = eRect(getAbsolutePosition(), size());
96         else
97                 m_state &= ~4;
98
99 //      eDebug("abs position %d %d -> %d %d", pos.left(), pos.top(), pos.width(), pos.height());
100
101         if (!disable && m_state & 8 && pos == m_user_rect)
102         {
103 //              eDebug("matched");
104                 return;
105         }
106
107         if (!(m_state & 1))
108         {
109                 m_user_rect = pos;
110                 m_state |= 1;
111 //              eDebug("set user rect pos!");
112         }
113
114 //      eDebug("m_user_rect %d %d -> %d %d", m_user_rect.left(), m_user_rect.top(), m_user_rect.width(), m_user_rect.height());
115
116         int left = pos.left() * 720 / m_fb_size.width();
117         int top = pos.top() * 576 / m_fb_size.height();
118         int width = pos.width() * 720 / m_fb_size.width();
119         int height = pos.height() * 576 / m_fb_size.height();
120
121         int tmp = left - (width * 4) / 100;
122         left = tmp < 0 ? 0 : tmp;
123         tmp = top - (height * 4) / 100;
124         top = tmp < 0 ? 0 : tmp;
125         tmp = (width * 108) / 100;
126         width = left + tmp > 720 ? 720 - left : tmp;
127         tmp = (height * 108) / 100;
128         height = top + tmp > 576 ? 576 - top : tmp;
129
130 //      eDebug("picture recalced %d %d -> %d %d", left, top, width, height);
131
132         if (!disable)
133         {
134                 for (int i=0; i<4; ++i)
135                 {
136                         const char *targets[]={"left", "top", "width", "height"};
137                         char filename[128];
138                         snprintf(filename, 128, "/proc/stb/vmpeg/%d/dst_%s", m_decoder, targets[i]);
139                         FILE *f = fopen(filename, "w");
140                         if (!f)
141                         {
142                                 eDebug("failed to open %s - %m", filename);
143                                 break;
144                         }
145                         int val = 0;
146                         {
147                                 switch (i)
148                                 {
149                                 case 0: val = left; break;
150                                 case 1: val = top; break;
151                                 case 2: val = width; break;
152                                 case 3: val = height; break;
153                                 }
154                                 fprintf(f, "%08x\n", val);
155                                 fclose(f);
156 //                              eDebug("%s %08x", filename, val);
157                         }
158                 }
159                 pendingFullsize &= ~(1 << m_decoder);
160                 m_state |= 8;
161         }
162         else
163         {
164                 m_state &= ~8;
165                 pendingFullsize |= (1 << m_decoder);
166                 fullsizeTimer->start(100, true);
167         }
168
169 }
170
171 void eVideoWidget::setDecoder(int decoder)
172 {
173         m_decoder = decoder;
174 }