From 99a3514072ef70c39683237664e8fffd4977590c Mon Sep 17 00:00:00 2001
From: chris <chris@flunder.ekke.wtal>
Date: Tue, 1 Jun 2010 00:47:48 +0200
Subject: [PATCH 2/5] fixing embed video on osx quartz renderer part1
This patch makes the quarz renderer to use of the calulations
of VideoOutWindow::GetDisplayVideoRect() for the desired parameters
instead repeating that code.
However, that will break video out in a resizeable window ... a
feature which isn't used by mythth ... it's a fullscreen application,
isn't it?
---
mythtv/libs/libmythtv/videoout_quartz.cpp | 156 +++++++++++------------------
1 files changed, 60 insertions(+), 96 deletions(-)
diff --git a/mythtv/libs/libmythtv/videoout_quartz.cpp b/mythtv/libs/libmythtv/videoout_quartz.cpp
index 450e945..78e8f15 100644
a
|
b
|
class VideoOutputQuartzView |
87 | 87 | |
88 | 88 | virtual void InputChanged(int width, int height, float aspect, |
89 | 89 | MythCodecID av_codec_id); |
90 | | virtual void MoveResize(QRect newRect); |
| 90 | virtual void MoveResize(); |
91 | 91 | |
92 | 92 | virtual void EmbedChanged(bool embedded); |
93 | 93 | |
94 | 94 | protected: |
95 | 95 | virtual bool Begin(void); |
96 | 96 | virtual void End(void); |
97 | | virtual void Transform(QRect newRect); |
| 97 | virtual void Transform(); |
98 | 98 | virtual void BlankScreen(bool deferred); |
99 | 99 | |
100 | 100 | // Subclasses implement the following methods: |
… |
… |
class VideoOutputQuartzView |
106 | 106 | QuartzData * parentData; // information about video source is here |
107 | 107 | |
108 | 108 | CGrafPtr thePort; // QuickDraw graphics port |
109 | | QRect m_desired; // Desired output size characteristics |
110 | 109 | ImageSequence theCodec; // QuickTime sequence ID |
111 | 110 | RgnHandle theMask; // clipping region |
112 | 111 | |
… |
… |
class QuartzData |
179 | 178 | Rect windowBounds; // dimensions, to restore size later |
180 | 179 | CGDirectDisplayID screen; // screen containing main window |
181 | 180 | float refreshRate; // for screen above |
| 181 | QRect display_rect; |
182 | 182 | |
183 | 183 | // Global preferences: |
184 | 184 | bool drawInWindow; // Fullscreen or in GUI view? |
… |
… |
bool VideoOutputQuartzView::Begin(void) |
222 | 222 | return false; |
223 | 223 | } |
224 | 224 | |
225 | | // Set initial output size |
226 | | Rect portBounds; |
227 | | GetPortBounds(thePort, &portBounds); |
228 | | VERBOSE(VB_PLAYBACK, QString("%0Viewport currently %1,%2 -> %3,%4") |
229 | | .arg(name).arg(portBounds.left).arg(portBounds.top) |
230 | | .arg(portBounds.right).arg(portBounds.bottom)); |
231 | | m_desired.setWidth(portBounds.right); |
232 | | m_desired.setHeight(portBounds.bottom); |
233 | 225 | #if 0 |
234 | 226 | // The clipping mask |
235 | 227 | theMask = NewRgn(); |
… |
… |
bool VideoOutputQuartzView::Begin(void) |
270 | 262 | viewLock.unlock(); |
271 | 263 | |
272 | 264 | // set transformation matrix |
273 | | Transform(m_desired); |
| 265 | Transform(); |
274 | 266 | |
275 | 267 | return true; |
276 | 268 | } |
… |
… |
void VideoOutputQuartzView::End(void) |
294 | 286 | } |
295 | 287 | |
296 | 288 | /// Build the transformation matrix to scale the video appropriately. |
297 | | void VideoOutputQuartzView::Transform(QRect newRect) |
| 289 | void VideoOutputQuartzView::Transform() |
298 | 290 | { |
299 | 291 | MatrixRecord matrix; |
300 | 292 | SetIdentityMatrix(&matrix); |
301 | 293 | |
302 | | int x, y, w, h, sw, sh; |
303 | | x = newRect.left(); |
304 | | y = newRect.top(); |
305 | | w = newRect.width(); |
306 | | h = newRect.height(); |
307 | | sw = parentData->srcWidth; |
308 | | sh = parentData->srcHeight; |
309 | | |
310 | | // constants for transformation operations |
311 | | Fixed one, zero; |
312 | | one = Long2Fix(1); |
313 | | zero = Long2Fix(0); |
314 | | |
315 | | VERBOSE(VB_PLAYBACK, QString("%0Viewport is %1 x %2") |
316 | | .arg(name).arg(w).arg(h)); |
317 | | VERBOSE(VB_PLAYBACK, QString("%0Image is %1 x %2") |
318 | | .arg(name).arg(sw).arg(sh)); |
319 | | |
320 | | double hscale = (double) w / sw; |
321 | | double vscale = (double) h / sh; |
322 | | |
323 | | // cap zooming if we requested it |
324 | | if (!parentData->scaleUpVideo) |
325 | | { |
326 | | double maxScale = fmax(hscale, vscale); |
327 | | hscale /= maxScale; |
328 | | vscale /= maxScale; |
329 | | } |
330 | | |
331 | | if ((hscale < 0.99) || (hscale > 1.01) || |
332 | | (vscale < 0.99) || (vscale > 1.01)) |
333 | | { |
334 | | VERBOSE(VB_PLAYBACK, QString("%0Scaling to %1 x %2 of original") |
335 | | .arg(name).arg(hscale).arg(vscale)); |
336 | | ScaleMatrix(&matrix, |
337 | | X2Fix(hscale), |
338 | | X2Fix(vscale), |
339 | | zero, zero); |
| 294 | Rect Rsrc, Rdst; |
| 295 | QRect display_rect; |
340 | 296 | |
341 | | // reset sw, sh for new apparent width/height |
342 | | sw = (int)(sw * hscale); |
343 | | sh = (int)(sh * vscale); |
344 | | } |
| 297 | Rsrc.left = 0; |
| 298 | Rsrc.top = 0; |
| 299 | Rsrc.right = parentData->srcWidth; |
| 300 | Rsrc.bottom = parentData->srcHeight; |
345 | 301 | |
346 | | // center image in viewport |
347 | | if ((h != sh) || (w != sw)) |
348 | | { |
349 | | VERBOSE(VB_PLAYBACK, QString("%0Centering with %1, %2") |
350 | | .arg(name).arg((w - sw)/2.0).arg((h - sh)/2.0)); |
351 | | TranslateMatrix(&matrix, X2Fix((w - sw) / 2.0), X2Fix((h - sh) / 2.0)); |
352 | | } |
| 302 | display_rect= parentData->display_rect; |
| 303 | Rdst.left = display_rect.left(); |
| 304 | Rdst.top = display_rect.top(); |
| 305 | Rdst.right = display_rect.right(); |
| 306 | Rdst.bottom = display_rect.bottom(); |
353 | 307 | |
354 | | // apply the basic sizing to DVDV |
355 | | #ifdef USING_DVDV |
356 | | if (parentData->dvdv) |
357 | | { |
358 | | parentData->dvdv->MoveResize( |
359 | | 0, 0, parentData->srcWidth, parentData->srcHeight, |
360 | | (int)((w - sw) / 2.0), (int)((h - sh) / 2.0), sw, sh); |
361 | | } |
362 | | #endif // USING_DVDV |
363 | | |
364 | | // apply graphics port or embedding offset |
365 | | if (x || y) |
366 | | { |
367 | | VERBOSE(VB_PLAYBACK, QString("%0Translating to %1, %2") |
368 | | .arg(name).arg(x).arg(y)); |
369 | | TranslateMatrix(&matrix, Long2Fix(x), Long2Fix(y)); |
370 | | } |
371 | | |
372 | | // Apply the transformation |
| 308 | MapMatrix(&matrix, &Rsrc, &Rdst); |
| 309 | #if 0 |
| 310 | VERBOSE(VB_PLAYBACK, QString("%0Viewport is now %1 / %2 / %3 / %4") |
| 311 | .arg(name) |
| 312 | .arg(Rdst.left) |
| 313 | .arg(Rdst.top) |
| 314 | .arg(Rdst.right) |
| 315 | .arg(Rdst.bottom) |
| 316 | ); |
| 317 | #endif |
373 | 318 | viewLock.lock(); |
374 | 319 | SetDSequenceMatrix(theCodec, &matrix); |
375 | 320 | viewLock.unlock(); |
… |
… |
void VideoOutputQuartzView::BlankScreen(bool deferred) |
388 | 333 | if (thePort) |
389 | 334 | { |
390 | 335 | SetPort(thePort); |
391 | | |
| 336 | #if 0 |
392 | 337 | // set clipping rectangle |
393 | 338 | Rect clipRect; |
394 | 339 | if (m_desired.width() && m_desired.height()) |
… |
… |
void VideoOutputQuartzView::BlankScreen(bool deferred) |
402 | 347 | { |
403 | 348 | GetPortBounds(thePort, &clipRect); |
404 | 349 | } |
| 350 | #endif |
| 351 | Rect clipRect; |
| 352 | GetPortBounds(thePort, &clipRect); |
| 353 | |
405 | 354 | RgnHandle clipRgn = NewRgn(); |
406 | 355 | RectRgn(clipRgn, &clipRect); |
407 | 356 | |
… |
… |
void VideoOutputQuartzView::InputChanged(int width, int height, float aspect, |
472 | 421 | Begin(); |
473 | 422 | } |
474 | 423 | |
475 | | void VideoOutputQuartzView::MoveResize(QRect newRect) |
| 424 | void VideoOutputQuartzView::MoveResize() |
476 | 425 | { |
477 | 426 | if (applyMoveResize) |
478 | | Transform(newRect); |
| 427 | Transform(); |
479 | 428 | } |
480 | 429 | |
481 | 430 | /// Subclasses that block the main window should suspend |
… |
… |
class VoqvEmbedded : public VideoOutputQuartzView |
576 | 525 | VoqvEmbedded(QuartzData *pData, int x, int y, int w, int h) |
577 | 526 | : VideoOutputQuartzView(pData) |
578 | 527 | { |
579 | | m_desired = QRect(x, y, w, h); |
| 528 | // m_desired = QRect(x, y, w, h); |
580 | 529 | name = "Embedded window: "; |
581 | 530 | }; |
582 | 531 | |
… |
… |
class VoqvDock : public VideoOutputQuartzView |
741 | 690 | "BeginQDContextForApplicationDockTile failed"); |
742 | 691 | return false; |
743 | 692 | } |
| 693 | |
744 | 694 | return true; |
745 | 695 | }; |
746 | 696 | |
… |
… |
class VoqvFloater : public VideoOutputQuartzView |
790 | 740 | // Resize complete, reset the window drawing transformation |
791 | 741 | Rect curBounds; |
792 | 742 | GetPortBounds(thePort, &curBounds); |
793 | | m_desired.setWidth(curBounds.right - curBounds.left); |
794 | | m_desired.setHeight(curBounds.bottom - curBounds.top); |
795 | | SetRectRgn(theMask, m_desired.left(), m_desired.top(), |
796 | | m_desired.width(), m_desired.height()); |
797 | | Transform(m_desired); |
| 743 | |
| 744 | VERBOSE(VB_IMPORTANT, "Fixme: resizing window"); |
| 745 | |
| 746 | // m_desired.setWidth(curBounds.right - curBounds.left); |
| 747 | // m_desired.setHeight(curBounds.bottom - curBounds.top); |
| 748 | // SetRectRgn(theMask, m_desired.left(), m_desired.top(), |
| 749 | // m_desired.width(), m_desired.height()); |
| 750 | Transform(); |
798 | 751 | } |
799 | 752 | resizing = startResizing; |
800 | 753 | } |
… |
… |
class VoqvDesktop : public VideoOutputQuartzView |
1056 | 1009 | viewLock.unlock(); |
1057 | 1010 | return false; |
1058 | 1011 | } |
| 1012 | |
1059 | 1013 | viewLock.unlock(); |
1060 | 1014 | ShowWindow(window); |
1061 | 1015 | // don't lose focus from main window |
… |
… |
VideoOutputQuartz::~VideoOutputQuartz() |
1130 | 1084 | |
1131 | 1085 | void VideoOutputQuartz::VideoAspectRatioChanged(float aspect) |
1132 | 1086 | { |
1133 | | VERBOSE(VB_PLAYBACK, (LOC + "VideoAspectRatioChanged(aspect=%1) [was %2]") |
1134 | | .arg(aspect).arg(data->srcAspect)); |
| 1087 | //VERBOSE(VB_PLAYBACK, (LOC + "VideoAspectRatioChanged(aspect=%1) [was %2]") |
| 1088 | // .arg(aspect).arg(data->srcAspect)); |
| 1089 | VERBOSE(VB_PLAYBACK, "QU: VideoAspectRatioChanged"); |
1135 | 1090 | |
1136 | 1091 | VideoOutput::VideoAspectRatioChanged(aspect); |
1137 | 1092 | |
… |
… |
void VideoOutputQuartz::ToggleAdjustFill(AdjustFillMode adjustFill) |
1155 | 1110 | |
1156 | 1111 | // We could change all the views, but the user probably only |
1157 | 1112 | // wants the main one (window or fullscreen) to change. |
1158 | | data->views[0]->MoveResize(windows[0].GetDisplayVideoRect()); |
| 1113 | data->views[0]->MoveResize(); |
1159 | 1114 | } |
1160 | 1115 | |
1161 | 1116 | void VideoOutputQuartz::MoveResize(void) |
… |
… |
void VideoOutputQuartz::MoveResize(void) |
1164 | 1119 | // the user's current aspect/fill/letterbox/zoom settings. |
1165 | 1120 | VideoOutput::MoveResize(); |
1166 | 1121 | |
1167 | | QRect newRect = windows[0].GetDisplayVideoRect(); |
| 1122 | const QSize video_dim = windows[0].GetVideoDim(); |
| 1123 | data->srcWidth = video_dim.width(); |
| 1124 | data->srcHeight = video_dim.height(); |
| 1125 | data->srcAspect = windows[0].GetVideoAspect(); |
| 1126 | data->srcMode = db_aspectoverride; |
| 1127 | data->display_rect = windows[0].GetDisplayVideoRect(); |
1168 | 1128 | |
1169 | 1129 | vector<VideoOutputQuartzView*>::iterator it; |
1170 | 1130 | for (it = data->views.begin(); it != data->views.end(); ++it) |
1171 | 1131 | { |
1172 | | (*it)->MoveResize(newRect); |
| 1132 | (*it)->MoveResize(); |
1173 | 1133 | } |
1174 | 1134 | } |
1175 | 1135 | |
… |
… |
bool VideoOutputQuartz::InputChanged(const QSize &input_size, |
1224 | 1184 | |
1225 | 1185 | data->srcWidth = video_dim.width(); |
1226 | 1186 | data->srcHeight = video_dim.height(); |
1227 | | data->srcAspect = aspect; |
| 1187 | data->srcAspect = windows[0].GetVideoAspect(); |
1228 | 1188 | data->srcMode = db_aspectoverride; |
| 1189 | data->display_rect = windows[0].GetDisplayVideoRect(); |
1229 | 1190 | |
1230 | 1191 | CreateQuartzBuffers(); |
1231 | 1192 | |
… |
… |
bool VideoOutputQuartz::Init(int width, int height, float aspect, |
1280 | 1241 | data->srcHeight = video_dim.height(); |
1281 | 1242 | data->srcAspect = aspect; |
1282 | 1243 | data->srcMode = db_aspectoverride; |
| 1244 | data->display_rect = windows[0].GetDisplayVideoRect(); |
1283 | 1245 | |
1284 | 1246 | // Initialize QuickTime |
1285 | 1247 | if (EnterMovies()) |
… |
… |
void VideoOutputQuartz::EmbedInWidget(int x, int y, int w, int h) |
1609 | 1571 | VideoOutput::EmbedInWidget(x, y, w, h); |
1610 | 1572 | |
1611 | 1573 | data->pixelLock.lock(); |
| 1574 | data->display_rect = windows[0].GetDisplayVideoRect(); |
1612 | 1575 | |
1613 | 1576 | // warn other views that embedding is starting |
1614 | 1577 | vector<VideoOutputQuartzView*>::iterator it = data->views.begin(); |
… |
… |
void VideoOutputQuartz::StopEmbedding(void) |
1638 | 1601 | VideoOutput::StopEmbedding(); |
1639 | 1602 | |
1640 | 1603 | data->pixelLock.lock(); |
| 1604 | data->display_rect = windows[0].GetDisplayVideoRect(); |
1641 | 1605 | |
1642 | 1606 | // delete embedded widget |
1643 | 1607 | if (data->embeddedView) |