Diffstat (limited to 'noncore/multimedia/opieplayer2/xinevideowidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/xinevideowidget.cpp | 166 |
1 files changed, 79 insertions, 87 deletions
diff --git a/noncore/multimedia/opieplayer2/xinevideowidget.cpp b/noncore/multimedia/opieplayer2/xinevideowidget.cpp index 211791b..7f59085 100644 --- a/noncore/multimedia/opieplayer2/xinevideowidget.cpp +++ b/noncore/multimedia/opieplayer2/xinevideowidget.cpp | |||
@@ -171,6 +171,9 @@ QSize XineVideoWidget::videoSize() const | |||
171 | 171 | ||
172 | void XineVideoWidget::paintEvent ( QPaintEvent * ) | 172 | void XineVideoWidget::paintEvent ( QPaintEvent * ) |
173 | { | 173 | { |
174 | if (m_bufmutex.isLocked()) { | ||
175 | return; | ||
176 | } | ||
174 | ThreadUtil::AutoLock a(m_bufmutex); | 177 | ThreadUtil::AutoLock a(m_bufmutex); |
175 | QPainter p ( this ); | 178 | QPainter p ( this ); |
176 | p. fillRect ( rect (), black ); | 179 | p. fillRect ( rect (), black ); |
@@ -181,13 +184,12 @@ void XineVideoWidget::paintEvent ( QPaintEvent * ) | |||
181 | void XineVideoWidget::paintEvent2 ( QPaintEvent * ) | 184 | void XineVideoWidget::paintEvent2 ( QPaintEvent * ) |
182 | { | 185 | { |
183 | ThreadUtil::AutoLock a(m_bufmutex); | 186 | ThreadUtil::AutoLock a(m_bufmutex); |
184 | if ( m_buff == 0 ) { | ||
185 | QPainter p ( this ); | 187 | QPainter p ( this ); |
188 | if ( m_buff == 0 ) { | ||
186 | p. fillRect ( rect ( ), black ); | 189 | p. fillRect ( rect ( ), black ); |
187 | if ( m_logo ) | 190 | if ( m_logo ) |
188 | p. drawImage ( 0, 0, *m_logo ); | 191 | p. drawImage ( 0, 0, *m_logo ); |
189 | } | 192 | } else if (m_lastsize){ |
190 | else { | ||
191 | // Qt needs to be notified which areas were really updated .. strange | 193 | // Qt needs to be notified which areas were really updated .. strange |
192 | QArray <QRect> qt_bug_workaround_clip_rects; | 194 | QArray <QRect> qt_bug_workaround_clip_rects; |
193 | 195 | ||
@@ -196,97 +198,85 @@ void XineVideoWidget::paintEvent2 ( QPaintEvent * ) | |||
196 | 198 | ||
197 | int rot = dp. transformOrientation ( ) + m_rotation; // device rotation + custom rotation | 199 | int rot = dp. transformOrientation ( ) + m_rotation; // device rotation + custom rotation |
198 | 200 | ||
201 | bool rot90 = (( -m_rotation ) & 1 ); | ||
202 | |||
203 | int _vw,_vh; | ||
204 | switch (rot90) { | ||
205 | case true: | ||
206 | _vh = m_framesize.width(); | ||
207 | _vw = m_framesize.height(); | ||
208 | break; | ||
209 | default: | ||
210 | _vw = m_framesize.width(); | ||
211 | _vh = m_framesize.height(); | ||
212 | break; | ||
213 | break; | ||
214 | } | ||
215 | int middle_w = _vw/2; | ||
216 | int middle_h = _vh/2; | ||
217 | m_thisframe.setRect(width()/2-middle_w,height()/2-middle_h,_vw,_vh); | ||
218 | QRect topFill,rightFill,leftFill,downFill; | ||
219 | topFill. setRect(0,0 ,width(),m_thisframe.top()); | ||
220 | downFill.setCoords(0,m_thisframe.bottom(),width(),height()); | ||
221 | rightFill.setCoords(m_thisframe.right(),0,width(),height()); | ||
222 | leftFill.setCoords(0,0,m_thisframe.left(),height()); | ||
223 | |||
224 | if (topFill.isValid()) { | ||
225 | p.fillRect(topFill,black); | ||
226 | } | ||
227 | if (downFill.isValid()) { | ||
228 | p.fillRect(downFill,black); | ||
229 | } | ||
230 | if (rightFill.isValid()) { | ||
231 | p.fillRect(rightFill,black); | ||
232 | } | ||
233 | if (leftFill.isValid()) { | ||
234 | p.fillRect(leftFill,black); | ||
235 | } | ||
199 | uchar *fb = dp. frameBuffer ( ); | 236 | uchar *fb = dp. frameBuffer ( ); |
200 | uchar *frame = m_buff; | 237 | uchar *frame = m_buff; |
201 | 238 | ||
202 | // where is the video frame in fb coordinates | 239 | // where is the video frame in fb coordinates |
203 | QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); | 240 | QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), |
204 | 241 | qt_screen-> height ( ))); | |
205 | qt_bug_workaround_clip_rects. resize ( dp. numRects ( )); | ||
206 | |||
207 | for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) { | ||
208 | const QRect &clip = dp. rect ( i ); | ||
209 | 242 | ||
210 | qt_bug_workaround_clip_rects [ i ] = qt_screen-> mapFromDevice ( clip, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); | ||
211 | |||
212 | uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb ); // clip x/y in the fb | ||
213 | uchar *src = frame; | 243 | uchar *src = frame; |
244 | uchar * dst = fb+framerect.y()*m_bytes_per_line_fb+framerect.x()*m_bytes_per_pixel; | ||
214 | 245 | ||
215 | // Adjust the start the source data based on the rotation (xine frame) | 246 | for (int y=framerect.top();y<=framerect.bottom();++y) { |
216 | switch ( rot ) { | 247 | switch ( rot ) { |
217 | case 0: src += ((( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame )); break; | 248 | case 0: |
218 | case 1: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame ) + (( framerect. height ( ) - 1 ) * m_bytes_per_pixel )); break; | 249 | memcpy(dst,src,m_bytes_per_line_frame); |
219 | case 2: src += ((( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame ) + (( framerect. height ( ) - 1 ) * m_bytes_per_line_frame )); break; | 250 | src+=m_bytes_per_line_frame; |
220 | case 3: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame )); break; | 251 | break; |
221 | default: break; | 252 | case 1: |
253 | memcpy_step ( dst, src, m_thisframe.size().width(), m_bytes_per_line_frame ); | ||
254 | src -= m_bytes_per_pixel; | ||
255 | break; | ||
256 | case 2: | ||
257 | memcpy_rev ( dst, src, m_thisframe.size().width()); | ||
258 | src-=m_bytes_per_line_frame; | ||
259 | break; | ||
260 | case 3: | ||
261 | memcpy_step_rev ( dst, src, m_thisframe.size().width(), m_bytes_per_line_frame ); | ||
262 | src += m_bytes_per_pixel; | ||
263 | break; | ||
264 | default: | ||
265 | break; | ||
266 | } | ||
267 | dst += m_bytes_per_line_fb; | ||
222 | } | 268 | } |
223 | |||
224 | // all of the following widths/heights are fb relative (0deg rotation) | ||
225 | |||
226 | uint leftfill = 0; // black border on the "left" side of the video frame | ||
227 | uint framefill = 0; // "width" of the video frame | ||
228 | uint rightfill = 0; // black border on the "right" side of the video frame | ||
229 | uint clipwidth = clip. width ( ) * m_bytes_per_pixel; // "width" of the current clip rect | ||
230 | |||
231 | if ( clip. left ( ) < framerect. left ( )) | ||
232 | leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth; | ||
233 | if ( clip. right ( ) > framerect. right ( )) | ||
234 | rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth; | ||
235 | |||
236 | framefill = clipwidth - ( leftfill + rightfill ); | ||
237 | |||
238 | for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) { | ||
239 | if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) { | ||
240 | // "above" or "below" the video -> black | ||
241 | memset ( dst, 0, clipwidth ); | ||
242 | } | 269 | } |
243 | else { | ||
244 | if ( leftfill ) | ||
245 | memset ( dst, 0, leftfill ); // "left" border -> black | ||
246 | 270 | ||
247 | if ( framefill ) { // blit in the video frame | ||
248 | // see above for an explanation of the different memcpys | ||
249 | |||
250 | switch ( rot ) { | ||
251 | case 0: memcpy ( dst + leftfill, src, framefill & ~1 ); break; | ||
252 | case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; | ||
253 | case 2: memcpy_rev ( dst + leftfill, src, framefill ); break; | ||
254 | case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; | ||
255 | default: break; | ||
256 | } | ||
257 | } | ||
258 | if ( rightfill ) | ||
259 | memset ( dst + leftfill + framefill, 0, rightfill ); // "right" border -> black | ||
260 | } | ||
261 | |||
262 | dst += m_bytes_per_line_fb; // advance one line in the framebuffer | ||
263 | |||
264 | // advance one "line" in the xine frame data | ||
265 | switch ( rot ) { | ||
266 | case 0: src += m_bytes_per_line_frame; break; | ||
267 | case 1: src -= m_bytes_per_pixel; break; | ||
268 | case 2: src -= m_bytes_per_line_frame; break; | ||
269 | case 3: src += m_bytes_per_pixel; break; | ||
270 | default: break; | ||
271 | } | ||
272 | } | ||
273 | } | ||
274 | } | ||
275 | 271 | ||
276 | { | 272 | { |
277 | // QVFB hack by Martin Jones | 273 | // QVFB hack by Martin Jones |
278 | // We need to "touch" all affected clip rects with a normal QPainter in addition to the QDirectPainter | 274 | // We need to "touch" all affected clip rects with a normal QPainter in addition to the QDirectPainter |
279 | 275 | p.fillRect(QRect(mapFromGlobal (m_thisframe. topLeft ( )), m_thisframe.size ()),QBrush(NoBrush)); | |
280 | QPainter p ( this ); | ||
281 | |||
282 | for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) { | ||
283 | p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [ i ]. topLeft ( )), qt_bug_workaround_clip_rects [ i ]. size ( )), QBrush ( NoBrush )); | ||
284 | } | ||
285 | } | 276 | } |
286 | } | 277 | } |
287 | } | 278 | } |
288 | 279 | ||
289 | |||
290 | QImage *XineVideoWidget::logo ( ) const | 280 | QImage *XineVideoWidget::logo ( ) const |
291 | { | 281 | { |
292 | return m_logo; | 282 | return m_logo; |
@@ -303,31 +293,33 @@ void XineVideoWidget::setVideoFrame ( uchar* img, int w, int h, int bpl ) | |||
303 | { | 293 | { |
304 | // mutex area for AutoLock | 294 | // mutex area for AutoLock |
305 | { | 295 | { |
306 | if (m_bufmutex.isLocked()) { | 296 | if (m_bufmutex.isLocked()||w>width()||h>height()) { |
307 | // no time to wait - drop frame | 297 | // no time to wait - drop frame |
308 | return; | 298 | return; |
309 | } | 299 | } |
310 | ThreadUtil::AutoLock a(m_bufmutex); | 300 | ThreadUtil::AutoLock a(m_bufmutex); |
311 | bool rot90 = (( -m_rotation ) & 1 ); | 301 | bool rot90 = (( -m_rotation ) & 1 ); |
312 | int l = h*m_bytes_per_pixel*w; | 302 | int l = h*bpl; |
313 | if (l>m_lastsize) { | 303 | if (l!=m_lastsize) { |
314 | if (m_buff) { | 304 | if (m_buff) { |
315 | delete[]m_buff; | 305 | delete[]m_buff; |
316 | } | 306 | } |
307 | if (l>0) { | ||
317 | m_buff = new uchar[l]; | 308 | m_buff = new uchar[l]; |
309 | odebug << "Point to: " << (unsigned long)m_buff << oendl; | ||
318 | m_lastsize=l; | 310 | m_lastsize=l; |
311 | } else { | ||
312 | m_buff = 0; | ||
319 | } | 313 | } |
320 | 314 | } else if (l==0){ | |
321 | if ( rot90 ) { // if the rotation is 90 or 270 we have to swap width / height | 315 | delete[] m_buff; |
322 | int d = w; | 316 | m_buff = 0; |
323 | w = h; | ||
324 | h = d; | ||
325 | } | 317 | } |
326 | 318 | m_lastsize = l; | |
327 | m_lastframe = m_thisframe; | 319 | m_framesize = QSize(w,h); |
328 | m_thisframe. setRect (( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h ); | 320 | if (m_buff && m_lastsize) { |
329 | |||
330 | memcpy(m_buff,img,m_lastsize); | 321 | memcpy(m_buff,img,m_lastsize); |
322 | } | ||
331 | m_bytes_per_line_frame = bpl; | 323 | m_bytes_per_line_frame = bpl; |
332 | } // Release Mutex | 324 | } // Release Mutex |
333 | 325 | ||